?? sale2.c
字號:
return (inventory);
}
#endif /* End STOCK */
/*************************************************************/
/**------------------------------------------------**
** Computing the tax for trans.price **
** tax = sum*rate; **
**------------------------------------------------**/
long caltax(char flag, byte taxno, long sum)
{
long tax;
tax = 0;
if(flag && Tax[taxno].rate)
tax = Sale_Mul(sum, sysflag->sysdots, Tax[taxno].rate, VAT_TAX_DOTS+2, sysflag->tax_round, sysflag->sysdots);
return (tax);
}
/**********************************************************/
/**-----------------------------------------------**
** Calculate the VAT of trans.amount **
** vat = sum*rate/(1+rate)
**-----------------------------------------------**/
long calVAT(byte idx, long sum)
{
DoubleLong dl;
long vat;
long round;
long divisor;
vat = 0L;
if(VAT[idx].rate)
{
if(sysflag->tax_round == 0) /** round **/
round = 5;
else if(sysflag->tax_round == 1) /** round up **/
round = 9;
else //(sysflag->tax_round == 2) /** round off **/
round = 0;
L2DL(labs(sum),&dl,sysflag->sysdots);
// DL_Div(...);
// Sale_Mul2(...);
DL_Mul(&dl,VAT[idx].rate,VAT_TAX_DOTS+2);
divisor = getLong(VAT_TAX_DOTS+2) + VAT[idx].rate; /* Get the divisor(1+rate) */
DL_Div(&dl,divisor,VAT_TAX_DOTS+2,1,sysflag->sysdots);
if(dl.sign == POSITIVE)
DL_Add(&dl,round,dl.dots);
else
DL_Add(&dl,-round,dl.dots);
DL_Div(&dl,10,1,0,0);
vat = dl.lowlong;
}
return (sum<0?-vat:vat);
}
/***************************************************************************/
void Get_TVAT(void)
{
byte i;
if(sysflag->Tax_System)
{
for(i = 0; i < MAX_TAX_NUM; i ++)
tmpvars.TVATAmt[i] = caltax(1,i,tmpvars.saleAmt_TVAT[i]);
}
else
{
for(i = 0; i < MAX_VAT_NUM; i ++)
tmpvars.TVATAmt[i] = calVAT(i,tmpvars.saleAmt_TVAT[i]);
}
}
void sto_snd_buf(byte tmpid, byte flag, word nth, long amount);
/*----------------------------------------------------------------------*
* Update the structure variable tmpvars
* tsbf: The transaction buffer variable.
* mode: Incidate the VAT mode or the tax mode.
* 0: VAT mode
* 1: Tax mode
* sign: Athwart the operation or not.
* NEGATIVE: Athwart the operation.
* POSITIVE: Not athwart the operation.
*----------------------------------------------------------------------*/
void Update_Tmpvars(TRANSBUFFDEF tsbf, byte sign)
{
byte ID;
byte tax1flag;
byte tax2flag;
byte tax3flag;
byte taxflag[MAX_TAX_NUM];
byte vat_idx;
long amount;
long rate; /* The temporary rate */
long inc;
long total;
byte tmpid;
byte i, j;
ID = (tsbf.ID)&0x1F; /* Get the ID */
if(ID == TS_EC) /* Error correct operation, return */
return;
#ifdef REST_PLU_FUNC
if(ID == TS_PLU_DESC)
return;
if((ID == TS_RM_PLU_GIFT)||(ID == TS_PLU_GIFT))
return;
if((ID == TS_MENU_HEAD)||(ID == TS_MENU_REAR))
return;
// if((ID == TS_MENU_HEAD))
// return;
#endif
if((ID == TS_DEPT) || (ID == TS_PLU) || (ID == TS_RM_DEPT) || (ID == TS_RM_PLU)
|| (ID == TS_RF_ITEM_DEPT) || (ID == TS_RF_ITEM_PLU) || (ID == TS_RF_SUBT))
{
amount = Sale_Mul((sign == POSITIVE)?tsbf.price:-tsbf.price, sysflag->sysdots, tsbf.quantity, 3, (tsbf.flag)>>4, sysflag->sysdots);
}
else /* The amount equal to the price */
{
amount = (sign == POSITIVE)?tsbf.price:-tsbf.price;
}
if((ID != TS_RF_SUBT) && (ID != TS_PER_SUBT))
{
#ifdef REST_PLU_FUNC
if(ID != TS_MENU_REAR)
#endif
{
if(sysflag->Tax_System) /* Tax mode */
{
tmpvars.subtotal += amount;
if((ID != TS_RF_SUBT) && (ID != TS_PER_SUBT)) /* After sub total operation, not to update the taxable amount */
{
for(j =0; j< MAX_TAX_NUM; j++)
{
taxflag[j] = (tsbf.flag>>j)&0x01;
if(taxflag[j])
tmpvars.saleAmt_TVAT[j] += amount;
}
// tax1flag = (tsbf.flag)&0x01;
// tax2flag = ((tsbf.flag)&0x02)>>1;
// tax3flag = ((tsbf.flag)&0x04)>>2;
// if(tax1flag) tmpvars.saleAmt_TVAT[0] += amount;
// if(tax2flag) tmpvars.saleAmt_TVAT[1] += amount;
// if(tax3flag) tmpvars.saleAmt_TVAT[2] += amount;
}
tmpvars.netamt = tmpvars.subtotal;
for(j =0; j< MAX_TAX_NUM; j++)
{
tmpvars.netamt += caltax(1, j, tmpvars.saleAmt_TVAT[j]);
}
}
else /* VAT mode */
{
tmpvars.subtotal += amount;
if((ID != TS_RF_SUBT) && (ID != TS_PER_SUBT)) /* After sub total operation, not to update the taxable amount */
{
vat_idx = (tsbf.flag)&0x0F;
if(vat_idx)
tmpvars.saleAmt_TVAT[vat_idx-1] += amount;
}
tmpvars.netamt = tmpvars.subtotal;
}
}
switch(ID)
{
case TS_DEPT: /* Department normal operation */
case TS_VD_DEPT: /* Department VOID operation */
case TS_RM_DEPT: /* Department RETURN operation */
case TS_RF_ITEM_DEPT: /* Department Refund after item operation */
case TS_PER_ITEM_DEPT: /* Department Percent after item operation */
#ifdef AUTO_PER /* Support the department auto percent function */
case TS_AUTO_PER_DEPT: /* Department Auto Percent operation */
#endif /* End AUTO_PER */
tmpid = TS_DEPT;
break;
case TS_PLU: /* PLU normal operation */
case TS_VD_PLU: /* PLU VOID operation */
case TS_RM_PLU: /* PLU RETURN operation */
case TS_RF_ITEM_PLU: /* PLU Refund after item operation */
case TS_PER_ITEM_PLU: /* PLU Percent after item operation */
#ifdef AUTO_PER /* Support the department auto percent function */
case TS_AUTO_PER_PLU: /* PLU Auto Percent operation */
#endif /* End AUTO_PER */
tmpid = TS_PLU;
break;
#ifdef REST_PLU_FUNC
case TS_MENU_REAR: /* The menu operation */
tmpid = TS_MENU_REAR;
break;
#endif
default: /* This case will not occur */
tmpid = TS_NULL;
break;
}
sto_snd_buf(tmpid, tsbf.flag, tsbf.nth, amount);
}
else /* Sub total percent and refund, approtion the amount to each register record */
{
if(sign == POSITIVE)
{
rate = Sale_Div(amount, sysflag->sysdots, tmpvars.netamt, sysflag->sysdots, tsbf.flag>>4, 5);
// Calculate the rate, then apportion to each item.
total = 0;
for(i = 0; i < SndTnsBf_Len; i ++)
{
inc = Sale_Mul(BakTnsBf[i].price, sysflag->sysdots, rate, 5, tsbf.flag>>4, sysflag->sysdots);
BakTnsBf[i].quantity = inc; /* Store the increment */
total += inc;
if(sysflag->Tax_System == 0) /* In the VAT mode */
{
if(i == (SndTnsBf_Len-1)) /* Store the error to the last record */
{
BakTnsBf[i].quantity += amount - total;
}
}
else /* Tax mode */
{
;/* Reserved */
}
BakTnsBf[i].price += BakTnsBf[i].quantity;
}
}
else
{
for(i = 0; i < SndTnsBf_Len; i ++) /* Restore to the last operation value */
{
BakTnsBf[i].price -= BakTnsBf[i].quantity;
BakTnsBf[i].quantity = 0;
}
}
if(sysflag->Tax_System) /* Tax mode */
{
tmpvars.subtotal += amount;
memset(tmpvars.saleAmt_TVAT, 0, sizeof(long)*MAX_VAT_NUM);
for(i = 0; i < SndTnsBf_Len; i ++)
{
for(j =0; j < MAX_TAX_NUM; j++)
{
taxflag[j] = ((BakTnsBf[i].flag>>j)&0x01);
if(taxflag[j])
tmpvars.saleAmt_TVAT[j] += BakTnsBf[i].price;
}
// tax1flag = (BakTnsBf[i].flag)&0x01;
// tax2flag = ((BakTnsBf[i].flag)&0x02)>>1;
// tax3flag = ((BakTnsBf[i].flag)&0x04)>>2;
// if(tax1flag) tmpvars.saleAmt_TVAT[0] += BakTnsBf[i].price;
// if(tax2flag) tmpvars.saleAmt_TVAT[1] += BakTnsBf[i].price;
// if(tax3flag) tmpvars.saleAmt_TVAT[2] += BakTnsBf[i].price;
}
tmpvars.netamt = tmpvars.subtotal;
for(j =0; j < MAX_TAX_NUM; j++)
tmpvars.netamt += caltax(1, j, tmpvars.saleAmt_TVAT[0]);
}
else /* VAT mode */
{
tmpvars.subtotal += amount;
memset(tmpvars.saleAmt_TVAT, 0, sizeof(long)*MAX_VAT_NUM);
for(i = 0; i < SndTnsBf_Len; i ++)
{
vat_idx = (BakTnsBf[i].flag)&0x0F;
if(vat_idx)
tmpvars.saleAmt_TVAT[vat_idx-1] += BakTnsBf[i].price;
}
tmpvars.netamt = tmpvars.subtotal;
}
}
// Display the subtotal to the LCD.
Lcd_Disp_Subttl();
}
/* Store the item to the second transaction buffer */
void sto_snd_buf(byte tmpid, byte flag, word nth, long amount)
{
byte i;
for(i = 0; i < SndTnsBf_Len; i ++)
{
if( (tmpid == BakTnsBf[i].ID) && (flag == BakTnsBf[i].flag) && (nth == BakTnsBf[i].nth) ) /* The same item */
{
BakTnsBf[i].price += amount;
if(BakTnsBf[i].price == 0) /* Delete this record */
// 注: 假如說不進行刪除的話, 在進行測試的時候, 進行了重復性的交易后又進行EC, 那么這個無用的空間就會被累積下來.
// 如此不斷的累積, 最終造成了崩潰.
{
if(i != SndTnsBf_Len-1)
{
memcpy(&BakTnsBf[i], &BakTnsBf[i+1], (SndTnsBf_Len-1-i)*sizeof(TRANSBUFFDEF));
}
if(SndTnsBf_Len)
SndTnsBf_Len --;
}
return;
}
}
BakTnsBf[SndTnsBf_Len].ID = tmpid;
BakTnsBf[SndTnsBf_Len].flag = flag;
BakTnsBf[SndTnsBf_Len].nth = nth;
BakTnsBf[SndTnsBf_Len].price = amount;
BakTnsBf[SndTnsBf_Len].quantity = 0;
SndTnsBf_Len ++;
}
/* Update the tax/VAT transaction buffer */
void Update_TVAT_Buff(void)
{
byte i;
transtvat.flag = sysflag->Tax_System;
transtvat.round = sysflag->tax_round;
#ifdef VER_RSNT /* Support the Restaurant function */
if((work_mode == RSNT) && (currtable != NUL_VLU))
transtvat.table_no = currtable;
else
transtvat.table_no = NUL_VLU;
#else
transtvat.table_no = NUL_VLU;
#endif /* End VER_RSNT */
if(sysflag->Tax_System) /* Tax mode */
{
for(i = 0; i < MAX_TAX_NUM; i ++)
transtvat.rate[i] = Tax[i].rate;
}
else /* VAT mode */
{
for(i = 0; i < MAX_VAT_NUM; i ++)
transtvat.rate[i] = VAT[i].rate;
}
}
/**---------------------------------------------**
** Update the cash report
**---------------------------------------------**/
void Update_Cash_Rpt(void)
{
if(CurrMode != REGISTER) /* The training mode, return */
return;
switch(InCmd) {
case KD_CASH: /* Update the CASH report */
case KD_PCASH1:
case KD_PCASH2:
case KD_PCASH3:
case KD_PCASH4:
report.CashTotal += trans.amount;
PTD_report.CashTotal += trans.amount;
report.CashAmt += trans.amount;
PTD_report.CashAmt += trans.amount;
report.CashCount ++;
PTD_report.CashCount ++;
break;
case KD_CHECK: /* Update the CHECK report */
report.CheckTotal[Check_Idx] += trans.amount;
PTD_report.CheckTotal[Check_Idx] += trans.amount;
report.CheckAmt[Check_Idx] += trans.amount;
PTD_report.CheckAmt[Check_Idx] += trans.amount;
report.CheckCount[Check_Idx] ++;
PTD_report.CheckCount[Check_Idx] ++;
break;
case KD_CHARGE: /* Update the CHARGE report */
report.ChargeAmt[Charge_Idx] += trans.amount;
PTD_report.ChargeAmt[Charge_Idx] += trans.amount;
report.ChargeCount[Charge_Idx] ++;
PTD_report.ChargeCount[Charge_Idx] ++;
break;
case KD_MISC: /* Update the MISC report */
report.MiscTotal += trans.amount;
PTD_report.MiscTotal += trans.amount;
report.MiscAmt += trans.amount;
PTD_report.MiscAmt += trans.amount;
report.MiscCount ++;
PTD_report.MiscCount ++;
break;
#ifdef FCE_FUNC /* Support the FCE function */
case KD_FCE1:
case KD_FCE2:
case KD_FCE3:
case KD_FCE4:
case KD_FCE:
fce[FCE_Idx].count ++;
fce[FCE_Idx].PTD_count ++;
fce[FCE_Idx].ttlindwr += bak_fce_input;
fce[FCE_Idx].PTD_ttlindwr += bak_fce_input;
if(tmpvars.netamt < 0) /* The input is more than the sales total */
{
fce[FCE_Idx].chg += labs(tmpvars.netamt); /* Add the positive value */
fce[FCE_Idx].PTD_chg += labs(tmpvars.netamt); /* Add the positive value */
report.CashTotal += tmpvars.netamt;
PTD_report.CashTotal += tmpvars.netamt;
}
break;
#endif /* End FCE_FUNC */
}
}
/**---------------------------------------------**
** Update the sale report
**---------------------------------------------**/
void Update_Sale_Rpt(void)
{
byte i;
byte ID;
byte plink;
byte peridxtmp;
word Idx;
long amount;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -