<?php

function UpdateData() {
    global $objAxpDB;

    $objAxpDB->Allow_Update(false);
    switch($_REQUEST[mode]) {
         case "update":

            for($j=1; $j<count($_REQUEST['ftitem_codeD0']); $j++) {
                
                $strSQL['Update Harga Beli Price'][]="UPDATE tlbuying_price SET
                                                            fcold_buying_price=fcbuying_price,
                                                            fcbuying_price='".CCur($_REQUEST['fcbuying_priceD0'][$j])."',
                                                            ftmodified_user='{$_SESSION['username']}',fdmodified_date=now()
                                                        WHERE ftitem_code='{$_REQUEST['ftitem_codeD0'][$j]}' AND ftcurrency_code='{$_REQUEST['ftcurrency_codeD0'][$j]}' AND
                                                            fcbuying_price<>".CCur($_REQUEST['fcbuying_priceD0'][$j]);

                $strSQL['Update Harga Beli Discount'][]="UPDATE tlbuying_price SET
                                                            ffold_buying_discount=ffbuying_discount,
                                                            ffbuying_discount='".CCur($_REQUEST['ffbuying_discountD0'][$j])."',
                                                            ftmodified_user='{$_SESSION['username']}',fdmodified_date=now()
                                                        WHERE ftitem_code='{$_REQUEST['ftitem_codeD0'][$j]}' AND ftcurrency_code='{$_REQUEST['ftcurrency_codeD0'][$j]}' AND
                                                             ffbuying_discount<>".CCur($_REQUEST['ffbuying_discountD0'][$j]);
                 
                if(CCur($_REQUEST['fcbuying_priceD0'][$j])!=CCur($_REQUEST['fcbuying_pricexD0'][$j])) {
                    $ssql="INSERT INTO txbuying_price_change
                                            (
                                            fdtrans_date,ftitem_code,ftsupplier_code,
                                            ftitem_name,ftuom_code,fcold_buying_price,
                                            fcbuying_price,ftdescription,ftcreated_user,
                                            fdcreated_date,ftmodified_user,fdmodified_date,
                                            ftcurrency_code
                                            )
                                    SELECT
                                            NOW() AS fdtrans_date,'{$_REQUEST['ftitem_codeD0'][$j]}' AS ftitem_code,RIGHT('{$_REQUEST['ftitem_codeD0'][$j]}',4) AS  ftsupplier_code,
                                            '' AS ftitem_name,'' AS ftuom_code,'".CCur($_REQUEST['fcbuying_pricexD0'][$j])."' AS fcold_buying_price,
                                            '".CCur($_REQUEST['fcbuying_priceD0'][$j])."' AS fcbuying_price, '' AS ftdescription,'{$_SESSION['username']}' AS ftcreated_user,
                                            now() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,now() AS fdmodified_date,
                                            '".($_REQUEST['ftcurrency_codeD0'][$j])."' AS ftcurrency_code  ";
                    $strSQL['INSERT txbuying_price_change'][]=$ssql;
                }

            }
            break;
    }

    return $strSQL;
}



?>
