SHARE
TWEET

update_qty_denied

Yudhistiragilang Jul 18th, 2019 (edited) 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /* * ********************************************************************
  4.   Copyright (C) FrontAccounting, LLC.
  5.   Released under the terms of the GNU General Public License, GPL,
  6.   as published by the Free Software Foundation, either version 3
  7.   of the License, or (at your option) any later version.
  8.   This program is distributed in the hope that it will be useful,
  9.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11.   See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
  12.  * ********************************************************************* */
  13. //---------------------------------------------------------------------------
  14. //
  15. //  Entry/Modify Denied Customer for DO Logistik
  16. //
  17.  
  18. $page_security = 'SA_SALESCREDITINV';
  19. $path_to_root = "..";
  20.  
  21. include_once($path_to_root . "/sales/includes/cart_class.inc");
  22. include_once($path_to_root . "/includes/session.inc");
  23. include_once($path_to_root . "/includes/data_checks.inc");
  24. include_once($path_to_root . "/includes/manufacturing.inc");
  25. include_once($path_to_root . "/sales/includes/sales_db.inc");
  26. include_once($path_to_root . "/sales/includes/sales_ui.inc");
  27. include_once($path_to_root . "/reporting/includes/reporting.inc");
  28.  
  29. $js = "";
  30. if ($use_popup_windows) {
  31.     $js .= get_js_open_window(900, 500);
  32. }
  33.  
  34. if ($use_date_picker) {
  35.     $js .= get_js_date_picker();
  36. }
  37.  
  38. if (isset($_GET['Id_Denied'])) {
  39.     $_SESSION['page_title'] = _($help_context = "Denied Customer Entry");
  40.     processing_start();
  41. }
  42. page($_SESSION['page_title'], false, false, "", $js);
  43.  
  44. //-----------------------------------------------------------------------------
  45.  
  46. if (isset($_GET['AddedID'])) {
  47.     $denied_no = $_GET['AddedID'];
  48.     $trans_type = ST_CUSTDENIED;
  49.  
  50.     display_notification_centered(_("Denied Customer has been processed"));
  51. //    display_note(get_customer_trans_view_str($trans_type, $denied_no, _("&View This Credit Note")), 0, 0);
  52.  
  53.     display_footer_exit();
  54. }else{
  55.     check_edit_conflicts();
  56. }
  57.  
  58. //-----------------------------------------------------------------------------
  59.  
  60. function can_process() {
  61.     global $Refs;
  62.  
  63.     if (!is_date($_POST['DeniedDate'])) {
  64.         display_error(_("The entered date is invalid."));
  65.         ;
  66.         set_focus('DeniedDate');
  67.         return false;
  68.     } elseif (!is_date_in_fiscalyear($_POST['DeniedDate'])) {
  69.         display_error(_("The entered date is not in fiscal year."));
  70.         set_focus('DeniedDate');
  71.         return false;
  72.     }
  73.    
  74.     if (!check_quantities()) {
  75.         display_error(_("Selected quantity cannot be less than zero nor more than quantity not credited yet."));
  76.         return false;
  77.     }
  78.    
  79.     $qty_kosong = true;
  80.     foreach ($_SESSION['Items']->line_items as $line_no => $itm) {
  81.         if($itm->qty_dispatched > 0){
  82.             $qty_kosong = false;
  83.        
  84.             $stock_coa = get_stock_gl_code($itm->stock_id);
  85.             if(empty($stock_coa['barang_hilang_account'])){
  86.                 display_error("Akun barang hilang item ".get_item_name($itm->stock_id)." belum disetting");
  87.                 return false;
  88.             }
  89.             if(empty($stock_coa['retur_sales_account'])){
  90.                 display_error("Akun retur sales item ".get_item_name($itm->stock_id)." belum disetting");
  91.                 return false;
  92.             }
  93.             if(empty($stock_coa['bonus_penjualan_account'])){
  94.                 display_error("Akun bonus penjualan item ".get_item_name($itm->stock_id)." belum disetting");
  95.                 return false;
  96.             }
  97.         }
  98.     }
  99.     if($qty_kosong){
  100.         display_error("qty harus diisi minimal satu");
  101.         return false;
  102.     }
  103.     return true;
  104. }
  105.  
  106. //-----------------------------------------------------------------------------
  107.  
  108. if (isset($_GET['Id_Denied']) && $_GET['Id_Denied'] > 0) {
  109.    
  110.     $row = get_retur_note($_GET['Id_Denied']);
  111.     $no_spj = $row['no_spj'];
  112.     $denied_memo = $row['memo_retur'];
  113.     $gudang_tujuan = $row['gudang_tujuan'];
  114.     $gudang_asal = $row['gudang_asal'];
  115.     $qty_denied = $row['qty_item'];
  116.    
  117.     $res_data = get_do(ID_PT_APPS, $row['no_spj']);
  118.     $data_no_do = array();
  119.     foreach ($res_data as $p) {
  120.         $data_no_do[] = $p['id_trans_do'];
  121.     $shipment_date[] = $p['shipment_date'];
  122.     $reference[] = $p['reference'];
  123.     }
  124.     $no_do = $data_no_do;
  125.     $shiping_date = $shipment_date[0];
  126.     $ref_spj = $reference[0];
  127.  
  128. //    $_SESSION['Items'] = new Cart(ST_SALESINVOICE, $_GET['Id_Denied'], true);
  129.     $_SESSION['Items'] = new Cart(ST_CUSTDENIED, $no_do, true);
  130.     copy_from_cart();
  131.    
  132. } elseif (!processing_active()) {
  133.    
  134.     /* This page can only be called with an invoice number for denied */
  135.     die(_("This page can only be opened if an invoice has been selected for denieded."));
  136.    
  137. } elseif (!check_quantities()) {
  138.    
  139.     display_error(_("Selected quantity cannot be less than zero nor more than quantity not credited yet."));
  140.    
  141. }
  142.  
  143. function check_quantities() {
  144.     $ok = 1;
  145.     foreach ($_SESSION['Items']->line_items as $line_no => $itm) {
  146.         if ($itm->quantity == $itm->qty_done) {
  147.             continue; // this line was fully credited/removed
  148.         }
  149.         if (isset($_POST['Line' . $line_no])) {
  150.             if (check_num('Line' . $line_no, 0, $itm->quantity)) {
  151.                 $_SESSION['Items']->line_items[$line_no]->qty_dispatched = input_num('Line' . $line_no);
  152.             } else {
  153.                 $ok = 0;
  154.             }
  155.         }
  156.  
  157.         if (isset($_POST['Line' . $line_no . 'Desc'])) {
  158.             $line_desc = $_POST['Line' . $line_no . 'Desc'];
  159.             if (strlen($line_desc) > 0) {
  160.                 $_SESSION['Items']->line_items[$line_no]->item_description = $line_desc;
  161.             }
  162.         }
  163.     }
  164.     return $ok;
  165. }
  166.  
  167. //-----------------------------------------------------------------------------
  168.  
  169. function copy_to_cart() {
  170.     $cart = &$_SESSION['Items'];
  171.     $cart->ship_via = $_POST['ShipperID'];
  172.     $cart->freight_cost = input_num('ChargeFreightCost');
  173.     $cart->document_date = $_POST['DeniedDate'];
  174.     $cart->Location = (isset($_POST['Location']) ? $_POST['Location'] : "");
  175.     $cart->Comments = $_POST['deniedMemo'];
  176.     $cart->is_bonus_cn = isset($_POST['is_bonus'])?$_POST['is_bonus']:0;
  177.     if ($_SESSION['Items']->trans_no == 0)
  178.         $cart->reference = $_POST['ref'];
  179. }
  180.  
  181. //-----------------------------------------------------------------------------
  182.  
  183. function copy_from_cart() {
  184.     $cart = &$_SESSION['Items'];
  185.     $_POST['ShipperID'] = $cart->ship_via;
  186.     $_POST['ChargeFreightCost'] = price_format($cart->freight_cost);
  187.     $_POST['DeniedDate'] = $cart->document_date;
  188.     $_POST['Location'] = $cart->Location;
  189.     $_POST['deniedMemo'] = $cart->Comments;
  190.     $_POST['cart_id'] = $cart->cart_id;
  191.     $_POST['ref'] = $cart->reference;
  192.     $_POST['is_bonus'] = $cart->is_bonus_cn;
  193. }
  194.  
  195. //-----------------------------------------------------------------------------
  196.  
  197. if (isset($_POST['ProcessDenied']) && can_process()) {
  198.     $new_denied = ($_SESSION['Items']->trans_no == 0);
  199.    
  200.     $trans_type = ($_SESSION['Items']->trans_type = ST_CUSTDENIED);
  201.    
  202.     if (!isset($_POST['WriteOffGLCode']))
  203.         $_POST['WriteOffGLCode'] = 0;
  204.  
  205.     copy_to_cart();
  206.     if ($new_denied)
  207.         new_doc_date($_SESSION['Items']->document_date);
  208.    
  209.     $is_bonus_cn = isset($_POST['is_bonus'])?$_POST['is_bonus']:0;
  210.     $denied_no = $_SESSION['Items']->write($_POST['WriteOffGLCode'], false, $is_bonus_cn, $_POST['DeniedType']);
  211.     if ($denied_no == -1) {
  212.         display_error(_("The entered reference is already in use."));
  213.         set_focus('ref');
  214.     } elseif ($denied_no) {
  215.         processing_end();
  216.         if ($new_denied) {
  217.             meta_forward($_SERVER['PHP_SELF'], "AddedID=$denied_no");
  218.         }
  219.     }
  220. }
  221.  
  222. //-----------------------------------------------------------------------------
  223.  
  224. if (isset($_POST['Location'])) {
  225.     $_SESSION['Items']->Location = $_POST['Location'];
  226. }
  227.  
  228. //-----------------------------------------------------------------------------
  229.  
  230. function display_denied_items() {
  231.     global $no_do, $no_spj, $shiping_date, $ref_spj, $qty_denied;
  232.    
  233.     start_form();
  234.     hidden('cart_id');
  235.     if(isset($_GET['Id_Denied'])){
  236.         $_POST['idDenied'] = $_GET['Id_Denied'];
  237.        
  238.     }
  239.     hidden('idDenied', $_POST['idDenied']);
  240.    
  241.     start_table(TABLESTYLE2, "width=80%", 5);
  242.     echo "<tr><td>"; // outer table
  243.  
  244.     start_table(TABLESTYLE, "width=100%");
  245.     start_row();
  246.     label_cells(_("Customer"), $_SESSION['Items']->cust_name, "class='tableheader2'");
  247.     label_cells(_("Branch"), get_branch_name($_SESSION['Items']->Branch), "class='tableheader2'");
  248.     end_row();
  249.     start_row();
  250.    
  251.     hidden('is_bonus', 0);
  252.    
  253.     label_cells(_("#SPJ"), $no_spj, "class='tableheader2'");
  254.  
  255.     if (!isset($_POST['ShipperID'])) {
  256.         $_POST['ShipperID'] = $_SESSION['Items']->ship_via;
  257.     }
  258.    
  259.     label_cells(_("Reference SPJ"), $ref_spj, "class='tableheader2'");    
  260.    
  261.     end_row();
  262.     end_table();
  263.  
  264.     echo "</td><td>"; // outer table
  265.  
  266.     start_table(TABLESTYLE, "width=100%");
  267.    
  268.     if ($_SESSION['Items']->trans_no > 0) {
  269.         label_row(_("Reference"), $_SESSION['Items']->reference, "class='tableheader2'");
  270.     }
  271.    
  272.     label_row(_("Shiping date"), $shiping_date, "class='tableheader2'");
  273.     label_row(_("Qty Denied"), $qty_denied, "class='tableheader2'");
  274.  
  275.     end_table();
  276.  
  277.     echo "</td></tr>";
  278.  
  279.     end_table(1); // outer table
  280.  
  281.     div_start('denied_items');
  282.     start_table(TABLESTYLE, "width=80%");
  283.     $th = array(_("Item Code"), _("Item Description"), _("Invoiced Quantity"), _("Units"),
  284.         _("Credit Quantity"), _("Price"), _("Total"));
  285. //  _("Credit Quantity"), _("Price"), _("Discount %"), _("Total"));
  286.     table_header($th);
  287.  
  288.     $k = 0; //row colour counter
  289.  
  290.     foreach ($_SESSION['Items']->line_items as $line_no => $ln_itm) {
  291.         if ($ln_itm->quantity == $ln_itm->qty_done) {
  292.             continue; // this line was fully credited/removed
  293.         }
  294.         alt_table_row_color($k);
  295.    
  296.         label_cell($ln_itm->stock_id);
  297.         text_cells(null, 'Line' . $line_no . 'Desc', $ln_itm->item_description, 30, 50);
  298.         $dec = get_qty_dec($ln_itm->stock_id);
  299.         qty_cell($ln_itm->quantity, false, $dec);
  300.         label_cell($ln_itm->units);
  301.         amount_cells(null, 'Line' . $line_no, number_format2($ln_itm->qty_dispatched, $dec), null, null, $dec);
  302.     $line_total = ($ln_itm->qty_dispatched * $ln_itm->price);
  303.         amount_cell($ln_itm->price);
  304.         amount_cell($line_total);
  305.         end_row();
  306.     }
  307.  
  308.     if (!check_num('ChargeFreightCost')) {
  309.         $_POST['ChargeFreightCost'] = price_format($_SESSION['Items']->freight_cost);
  310.     }
  311.     $colspan = 6;
  312.    
  313.     $inv_items_total = $_SESSION['Items']->get_items_total_dispatch();
  314.  
  315.     $display_sub_total = price_format($inv_items_total + input_num($_POST['ChargeFreightCost']));
  316.     label_row(_("Sub-total"), $display_sub_total, "colspan=$colspan align=right", "align=right");
  317.     $display_total = price_format(($inv_items_total + input_num('ChargeFreightCost')));
  318.  
  319.     label_row(_("Denied Customer Total"), $display_total, "colspan=$colspan align=right", "align=right");
  320.  
  321.     end_table();
  322.     div_end();
  323. }
  324.  
  325. //-----------------------------------------------------------------------------
  326. function display_credit_options() {
  327.     global $Ajax, $denied_memo, $gudang_tujuan, $gudang_asal;
  328.     br();
  329.  
  330.     if (isset($_POST['_DeniedType_update']))
  331.         $Ajax->activate('options');
  332.  
  333.     div_start('options');
  334.     start_table(TABLESTYLE2);
  335.    
  336.     label_row(_("Gudang Asal :"), _gudang($gudang_asal), "class='tableheader1'");
  337.     label_cells(_("Gudang Tujuan :"), _gudang($gudang_tujuan), "class='tableheader1'");
  338.    
  339.     textarea_row(_("Memo"), "deniedMemo", $denied_memo, 51, 3);
  340.     echo "</table>";
  341.     div_end();
  342. }
  343.  
  344. function get_data_retur_note($url)
  345. {
  346.     $curl = curl_init();
  347.     curl_setopt($curl, CURLOPT_URL, $url);
  348.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  349.     $result = curl_exec($curl);
  350.     curl_close($curl);
  351.     return json_decode($result, true);
  352. }
  353.  
  354. function get_do( $pt_id, $no_spj)
  355. {  
  356.    $params = array(
  357.       "pt_id=".$pt_id,
  358.       "id_spj=".$no_spj
  359.     );
  360.    $result = get_data_retur_note(set_url_to_get_data("shipment-done/denied-customer", ID_PT_LOGISTIK ,$params));  
  361.    return $result['data'];
  362. }
  363.  
  364. function get_retur_note($id){
  365.     $sql = "SELECT * FROM 0_retur_note WHERE id=".$id;
  366.     $result = db_query($sql, "Cannot select datas");
  367.     $row = db_fetch($result);
  368.     return $row;
  369. }
  370.  
  371. function _gudang($loc_code){
  372.     $sql = "SELECT location_name FROM ".TB_PREF."locations WHERE loc_code='".$loc_code."'";
  373.     $query = db_query($sql);
  374.    
  375.     while ($row = db_fetch($query)) {
  376.         $gudang = $row['location_name'];
  377.     }
  378.     return $gudang;
  379. }
  380.  
  381. //-----------------------------------------------------------------------------
  382. if (get_post('Update')) {
  383.     $Ajax->activate('denied_items');
  384. }
  385. //-----------------------------------------------------------------------------
  386.  
  387. display_denied_items();
  388. display_credit_options();
  389.  
  390. echo "<br><center>";
  391. submit('Update', _("Update"), true, _('Update denied value for quantities entered'), true);
  392. echo "&nbsp";
  393. submit('ProcessDenied', _("Process Denied Customer"), true, '', 'default');
  394. echo "</center>";
  395.  
  396. end_form();
  397. end_page();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top