?? sale2.c
字號:
/*
* Module: SALE2.C
* Modified by: X.C.Zheng WeiHua
* Modified on: Date: 2004-02-10 14:48
* Copyright(c) WeiHua Tech Ltd.
*/
#include "ecrsys.h"
#include "ftype.h"
#include "sysdata.h"
#include "data.h"
#include "mathes.h"
#include "stdlib.h"
#include "disp.h"
#include "keydef.h"
#include <string.h>
void Sale_Test(void)
{
InitTrans();
TnsBf_Len = 0;
transbuff[TnsBf_Len].ID = TS_DEPT;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 1300;
transbuff[TnsBf_Len].quantity = 2000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_PER_ITEM_DEPT;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 2600;
transbuff[TnsBf_Len].quantity = 20;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_RF_ITEM_DEPT;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 1300;
transbuff[TnsBf_Len].quantity = 1000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_PLU;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 100;
transbuff[TnsBf_Len].price = 1500;
transbuff[TnsBf_Len].quantity = 10000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_PER_ITEM_PLU;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 100;
transbuff[TnsBf_Len].price = 15000;
transbuff[TnsBf_Len].quantity = 10;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_RF_ITEM_PLU;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 100;
transbuff[TnsBf_Len].price = 1500;
transbuff[TnsBf_Len].quantity = 1000;
Sale_Dsp(transbuff[TnsBf_Len]);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_VD_PLU;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 1000;
transbuff[TnsBf_Len].quantity = 1000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_VD_DEPT;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 2000;
transbuff[TnsBf_Len].quantity = 1000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_RM_PLU;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 1300;
transbuff[TnsBf_Len].quantity = 2000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_RM_DEPT;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 1300;
transbuff[TnsBf_Len].quantity = 2000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_EC;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 13000;
transbuff[TnsBf_Len].quantity = 1000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_RF_SUBT;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 13000;
transbuff[TnsBf_Len].quantity = 1000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
transbuff[TnsBf_Len].ID = TS_PER_SUBT;
transbuff[TnsBf_Len].flag = 0;
transbuff[TnsBf_Len].nth = 20;
transbuff[TnsBf_Len].price = 13000;
transbuff[TnsBf_Len].quantity = 1000;
Sale_Dsp(transbuff[TnsBf_Len]);
Wait(1000);
TnsBf_Len++;
}
/*----------------------------------------------------------------------*
* Do the sale mode multiplication.
* l1: The multiplicand.
* dots1: The multiplicand's decimal dots (0~8).
* l2: The multiplier.
* dots2: The multiplier's decimal dots (0~8).
* round: The operation roundings.
* 0: round
* 1: Round up
* 2: Cut off
* dots3: The return data's decimal dots (0~8).
*
* return:
* 0x80000000: The result is illlegal or too big.
*----------------------------------------------------------------------*/
long Sale_Mul(long l1, byte dots1, long l2, byte dots2, byte round, byte dots3)
{
DoubleLong dl;
long tmp;
if((l1 == MIN_SIGNED_LONG) || (l2 == MIN_SIGNED_LONG))
return (MIN_SIGNED_LONG);
if((dots1 > 8) || (dots2 > 8) ||(dots3 > 8) || (dots1+dots2-dots3 > 9))
return (MIN_SIGNED_LONG);
if(round > 2)
return (MIN_SIGNED_LONG);
L2DL(l1, &dl, dots1); /* Transform it to double long */
Sale_Mul2(&dl, l2, dots2, round, dots3);
if((dl.highlong != 0) || ((dl.lowlong&0x80000000) != 0)) /* Too big */
tmp = MIN_SIGNED_LONG;
else
tmp = dl.lowlong;
if(dl.sign == NEGATIVE) /* Negative result */
tmp = -tmp;
return (tmp);
}
/*----------------------------------------------------------------------*
* Do the sale mode multiplication.
* ll: The multiplicand.
* l2: The multiplier.
* dots2: The multiplier's decimal dots (0~8).
* round: The operation roundings.
* 0: round
* 1: Round up
* 2: Cut off
* dots3: The return data's decimal dots (0~8).
*
* return:
* NOTOK: The result is illlegal.
* OK: The result is legal.
*----------------------------------------------------------------------*/
byte Sale_Mul2(DoubleLong *ll, long l2, byte dots2, byte round, byte dots3)
{
long cal_round;
if(l2 == MIN_SIGNED_LONG)
return (NOTOK);
if((dots2 > 8) || (dots3 > 8))
return (NOTOK);
if(round > 2)
return (NOTOK);
if(DL_Mul(ll, l2, dots2) == NOTOK)
return (NOTOK);
if(ll->dots > dots3) /* Get the round operation data */
{
if(round == 0)
cal_round = 5 * getLong(ll->dots - dots3 - 1);
else if(round == 1)
cal_round = 9 * getLong(ll->dots - dots3 - 1);
else
cal_round = 0;
}
else
cal_round = 0;
if(ll->sign == POSITIVE) /* Add to the round */
DL_Add(ll, cal_round, ll->dots);
else
DL_Add(ll, -cal_round, ll->dots);
if(ll->dots > dots3) /* Adjust the result */
DL_Div(ll, getLong(ll->dots - dots3), ll->dots - dots3, 0, 0);
else if(ll->dots < dots3)
{
if(DL_Mul(ll, getLong(ll->dots - dots3), ll->dots - dots3) == NOTOK)
return (NOTOK);
}
return (OK);
}
/*----------------------------------------------------------------------*
* Do the sale mode division.
* l1: The dividend.
* dots1: The dividend's decimal dots (0~8).
* l2: The divisor.
* dots2: The divisor's decimal dots (0~8).
* round: The operation roundings.
* 0: round
* 1: Round up
* 2: Cut off
* dots3: The return data's decimal dots (0~8).
*
* return:
* 0x80000000: The result is illlegal or too big.
*----------------------------------------------------------------------*/
long Sale_Div(long l1, byte dots1, long l2, byte dots2, byte round, byte dots3)
{
DoubleLong dl;
long tmp;
long cal_round;
if((l1 == MIN_SIGNED_LONG) || (l2 == MIN_SIGNED_LONG))
return (MIN_SIGNED_LONG);
if((dots1 > 8) || (dots2 > 8) ||(dots3 > 8))
return (MIN_SIGNED_LONG);
if(round > 2)
return (MIN_SIGNED_LONG);
L2DL(l1, &dl, dots1); /* Transform it to double long */
if(DL_Exact_Div(&dl, l2, dots2) == NOTOK)
return (MIN_SIGNED_LONG);
while(dl.dots > 8) /* Adjust it to max 8 dots */
DL_Div(&dl, 10, 1, 0, 0);
if(dl.dots > dots3)
{
if(round == 0)
cal_round = 5 * getLong(dl.dots - dots3 - 1);
else if(round == 1)
cal_round = 9 * getLong(dl.dots - dots3 - 1);
else
cal_round = 0;
}
else
cal_round = 0;
if(dl.sign == POSITIVE)
DL_Add(&dl, cal_round, dl.dots);
else
DL_Add(&dl, -cal_round, dl.dots);
if(dl.dots > dots3) /* Adjust the result */
DL_Div(&dl, getLong(dl.dots - dots3), dl.dots - dots3, 0, 0);
else if(dl.dots < dots3)
{
if(DL_Mul(&dl, getLong(dots3 - dl.dots), dots3 - dl.dots) == NOTOK)
return (NOTOK);
}
if((dl.highlong != 0) || ((dl.lowlong&0x80000000) != 0)) /* Too big */
tmp = MIN_SIGNED_LONG;
else
tmp = dl.lowlong;
if(dl.sign == NEGATIVE) /* Negative result */
tmp = -tmp;
return (tmp);
}
/*--------------------------------------------------------------------------*
Calculate the transaction total quantity
*--------------------------------------------------------------------------*/
long calTotQty(TRANSBUFFDEF *tsbf, byte tsbf_len)
{
byte i;
long Tot_Qty;
Tot_Qty = 0;
for(i = 0; i < tsbf_len; i ++)
{
switch((tsbf[i].ID&0x1F))
{
case TS_DEPT: /* Department normal operation */
case TS_PLU: /* PLU normal normal operation */
Tot_Qty += tsbf[i].quantity; /* For the quantity is positive */
break;
case TS_RM_DEPT: /* Department Return Merchandise operation */
case TS_RM_PLU: /* PLU Return Merchandise operation */
Tot_Qty -= tsbf[i].quantity; /* For the quantity is positive */
break;
default:
break;
}
}
return (Tot_Qty);
}
/*-------------------------------------------------------------------------*
* Calculate the transaction buffer part amount.
* Parameter:
* Flag: The department or the PLU.
* DEPT: Select the department.
* PLU: Select the PLU.
* Idx: The department or the PLU index number.
*-------------------------------------------------------------------------*/
long calPrtAmt(byte Flag, word Idx)
{
byte i; /* The circular temporary variable */
byte ID;
long amount;
long Tot_Amt;
Tot_Amt = 0;
for( i = 0; i < TnsBf_Len; i ++)
{
ID = (transbuff[i].ID)&0x1F;
if(Flag == DEPT)
{
if((ID == TS_DEPT) || (ID == TS_VD_DEPT) || (ID == TS_RM_DEPT)
|| (ID == TS_RF_ITEM_DEPT) || (ID == TS_PER_ITEM_DEPT)
#ifdef AUTO_PER /* Support the department auto percent function */
|| (ID == TS_AUTO_PER_DEPT)
#endif /* End AUTO_PER */
)
{
if((ID == TS_DEPT) || (ID == TS_RM_DEPT) || (ID == TS_RF_ITEM_DEPT))
amount = Sale_Mul(transbuff[i].price, sysflag->sysdots, transbuff[i].quantity, 3, (transbuff[i].flag)>>4, sysflag->sysdots);
else
amount = transbuff[i].price; /* The amount equal to the price */
if(Idx == transbuff[i].nth)
Tot_Amt += amount;
}
}
else if(Flag == PLU)
{
if((ID == TS_PLU) || (ID == TS_VD_PLU) || (ID == TS_RM_PLU)
|| (ID == TS_RF_ITEM_PLU) || (ID == TS_PER_ITEM_PLU)
#ifdef AUTO_PER /* Support the department auto percent function */
|| (TS_AUTO_PER_PLU)
#endif /* End AUTO_PER */
)
{
if((ID == TS_PLU) || (ID == TS_RM_PLU) || (ID == TS_RF_ITEM_PLU))
amount = Sale_Mul(transbuff[i].price, sysflag->sysdots, transbuff[i].quantity, 3, (transbuff[i].flag)>>4, sysflag->sysdots);
else
amount = transbuff[i].price; /* The amount equal to the price */
if(Idx == transbuff[i].nth)
Tot_Amt += amount;
}
}
}
return (Tot_Amt);
}
#ifdef STOCK /* Support the PLU stock function */
/*----------------------------------------------------------------------*
Calculate the total PLU inventory from transbuff.
*----------------------------------------------------------------------*/
long calTotStk(word idx)
{
byte i;
byte ID;
long inventory;
inventory = plu[idx].inventory;
for(i = 0; i < TnsBf_Len; i ++)
{
ID = (transbuff[i].ID)&0x1F;
switch(ID)
{
case TS_PLU: /* PLU normal operation */
if(idx == transbuff[i].nth) /* Right PLU index number */
inventory -= transbuff[i].quantity;
break;
#ifdef REST_PLU_FUNC
case TS_PLU_GIFT: /* PLU gigt operation */
case TS_RM_PLU_GIFT: /* PLU gift operation */
if(idx == transbuff[i].nth) /* Right PLU index number */
inventory -= transbuff[i].quantity;
break;
#endif
case TS_RM_PLU: /* PLU Return Merchandise operation */
if(idx == transbuff[i].nth) /* Right PLU index number */
inventory += transbuff[i].quantity;
break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -