//หายอดlast year day ส่งไปเก็บที่ TABLE BSPM
$strSQL3 = "SELECT SUM(total) AS lyday ,user.zone,SUM(stdrecord.stdqty) AS qty,stdrecord.shopcode,user.payment,user.pro FROM stdrecord INNER JOIN user ON stdrecord.shopcode=user.user WHERE stdrecord.shopcode!='' AND stdrecord.type='s' AND stdrecord.date BETWEEN '".$laststart."' AND '".$lastend."' GROUP BY stdrecord.shopcode ORDER BY stdrecord.shopcode DESC";
$objQuery3 = mysql_query($strSQL3);
$objResult3 = mysql_fetch_array($objQuery3);
while($objResult3 = mysql_fetch_array($objQuery3))
{
//check shopcode if have is update no have insert
$strCHECKms = "SELECT shopcode FROM bspm WHERE shopcode = '".$objResult3["shopcode"]."' AND userid='".$objResultqq["userid"]."' ";
$objQueryCHECKms = mysql_query($strCHECKms);
$objResultCHECKms = mysql_fetch_array($objQueryCHECKms);
//ถ้ามีให้ปรับปรุง
if($objResultCHECKms["shopcode"] !="")
{
$result = mysql_query("update bspm set lyday = '".$objResult3["lyday"]."' WHERE shopcode = '".$objResult3["shopcode"]."' AND userid='".$objResultqq["userid"]."' ");
}
else
{ //group payment
if($objResult3["payment"]=='ROBINSON-407')
{ $acc= 'ROBINSON-407'; }
else if($objResult3["payment"]=='ROBINSON-409' OR $objResult3["payment"]=='ROBINSON-406')
{ $acc= 'ROBINSON-409'; }
else if($objResult3["payment"]=='BIG-C' OR $objResult3["payment"]=='BIG-C EXTRA')
{ $acc= 'BIG-C'; }
else if($objResult3["payment"]=='THE MALL-DP85' OR $objResult3["payment"]=='THE MALL-DP37' OR $objResult3["payment"]=='GMS')
{ $acc= 'THE MALL'; }
else if($objResult3["payment"]=='LOTUS')
{ $acc= 'LOTUS'; }
else if($objResult3["payment"]=='Online')
{ $acc= 'ONLINE'; }
else if($objResult3["payment"]=='CENTRAL')
{ $acc= 'CENTRAL'; }
else if($objResult3["payment"]=='KING POWER')
{ $acc= 'KING POWER'; }
else if($objResult3["payment"]=='SHOP' OR $objResult3["payment"]=='CASH' OR $objResult7["payment"]=='GP-CASH')
{ $acc= 'SHOP/CASH'; }
else if($objResult3["payment"]=='COLISEUM')
{ $acc= 'COLISEUM';}
else if($objResult3["payment"]=='GP-NONVAT' OR $objResult3["payment"]=='GP-VAT')
{ $acc= 'GP'; }
else
{ $acc= 'OTHER'; }