Exemplo n.º 1
0
 public function s003()
 {
     try {
         $req = App::request();
         if ($req->isPost()) {
             $post = $req->post();
             $rows = json_decode($post['rows'], true);
             if (!empty($post["entry_kode"])) {
                 if (is_null($post["gen_id"]) || $post["gen_id"] == "") {
                     $total_amount = 0;
                     $incoming = 0;
                     $outgoing = 0;
                     foreach ($rows as $row) {
                         $basic_amount = ZiUtil::check_int($row["item_amount"]);
                         // beda receipt dg transfer item_price ikut valuation rate
                         $basic_rate = ZiUtil::check_int($row["item_price"]);
                         $row["item_batch"] = !array_key_exists("item_batch", $row) ? null : $row["item_batch"];
                         $additional_cost = 0;
                         // valuation_rate
                         $amount_rate = $basic_rate + $additional_cost;
                         $amount = ZiUtil::check_int($row["item_qty"]) * $amount_rate;
                         $attr_detail = array("created" => date("Y-m-d H:i:s"), "stok_entry" => $post["entry_kode"], "to_warehouse" => $row["to_warehouse"], "from_warehouse" => $row["from_warehouse"], "item_kode" => $row["item_kode"], "item_nama" => $row["item_nama"], "item_uom" => $row["item_uom"], "batch_no" => $row["item_batch"], "keterangan" => $row["keterangan"], "actual_qty" => $row["actual_qty"], "qty" => $row["item_qty"], "basic_amount" => $basic_amount, "basic_rate" => $basic_rate, "valuation_rate" => $amount_rate, "additional_cost" => $additional_cost, "amount" => $amount);
                         $voucher_detail_no = ZiUtil::GetNowID();
                         $attr_detail["id"] = $voucher_detail_no;
                         $tableDetail = StokEntryD::table();
                         $tableDetail->insert($attr_detail);
                         // incoming
                         if (isset($row["to_warehouse"]) && !empty($row["to_warehouse"])) {
                             $incoming += $amount;
                             // insert stock_queue
                             // klo jenis transfer incoming_rate pake hasil dari valuation_rate
                             // receipt pake $amount_rate
                             $stock_queue = new ZiStockQueue();
                             $stock_queue->incoming_stock($row["item_kode"], $row["to_warehouse"], $amount_rate, $row["item_qty"], $row["item_batch"]);
                             $valuation_rate = ZiStockQueue::valuation_rate($row["item_kode"], $row["to_warehouse"], $row["item_batch"]);
                             $valuation_rate = $valuation_rate > 0 ? $valuation_rate : $amount_rate;
                             $qty_after_trans = ZiUtil::check_int($row["actual_qty"]) + ZiUtil::check_int($row["item_qty"]);
                             $stock_value_diff = ZiUtil::check_int($row["item_qty"]) * $amount_rate;
                             $stock_value = $qty_after_trans * $valuation_rate;
                             // saat nya entry data stock ledger
                             $stockLedger = new ZiStockLedger();
                             $stockLedger->insert_db($row["item_kode"], "Stock Entry", $post["entry_kode"], $voucher_detail_no, ZiUtil::check_int($row["item_qty"]), $row["to_warehouse"], $qty_after_trans, $valuation_rate, $stock_value, $stock_value_diff, $amount_rate, $row["item_batch"]);
                         }
                         // outgoing
                         if (isset($row["from_warehouse"]) && !empty($row["from_warehouse"])) {
                             $outgoing += $amount;
                             $stock_queue = new ZiStockQueue();
                             $stock_queue->outgoing_stock($row["item_kode"], $row["from_warehouse"], $row["item_qty"], $row["item_batch"]);
                             $valuation_rate = ZiStockQueue::valuation_rate($row["item_kode"], $row["from_warehouse"], $row["item_batch"]);
                             $valuation_rate = $valuation_rate > 0 ? $valuation_rate : $amount_rate;
                             $qty_after_trans = ZiUtil::check_int($row["actual_qty"]) - ZiUtil::check_int($row["item_qty"]);
                             $stock_value_diff = (0 - ZiUtil::check_int($row["item_qty"])) * $valuation_rate;
                             $stock_value = $qty_after_trans * $valuation_rate;
                             // $valuation_rate diperoleh dari total all incoming stock
                             // saat nya entry data stock ledger
                             $stockLedger = new ZiStockLedger();
                             $stockLedger->insert_db($row["item_kode"], "Stock Entry", $post["entry_kode"], $voucher_detail_no, 0 - ZiUtil::check_int($row["item_qty"]), $row["from_warehouse"], $qty_after_trans, $valuation_rate, $stock_value, $stock_value_diff, 0, $row["item_batch"]);
                         }
                         $total_amount += $amount;
                     }
                     $attr_master = array("created" => date("Y-m-d H:i:s"), "modified" => date("Y-m-d H:i:s"), "title" => "Material " . $post["stok_entry_tipe"], "naming_series" => "STE", "fiscal_year" => date('Y'), "company" => "RSMM", "posting_date" => $post["posting_date"], "posting_time" => $post["posting_time"], "stok_entry_kode" => $post["entry_kode"], "stok_entry_tipe" => $post["stok_entry_tipe"], "to_warehouse" => $post["to_warehouse"], "from_warehouse" => $post["from_warehouse"], "total_incoming_value" => $incoming, "total_outgoing_value" => $outgoing, "total_additional_costs" => 0, "value_difference" => $incoming - $outgoing);
                     $attr_master["total_amount"] = $total_amount;
                     $attr_master["id"] = ZiUtil::GetNowID();
                     $table = StokEntry::table();
                     $table->insert($attr_master);
                 }
                 App::flash('info', 'Data Tersimpan.');
                 App::redirect('stok.list_stock_entry');
             }
         }
         App::flash('error', 'Terjadi kesalahan pada inputan anda.');
         App::redirect('stok.entry');
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
     }
 }
Exemplo n.º 2
0
 public function s003()
 {
     try {
         $req = App::request();
         if ($req->isPost()) {
             $post = $req->post();
             $rows = json_decode($post['rows'], true);
             // Generate Kode Sales Invoice (SINV-030-20151204-xxxxx)
             $kode_invoice = $post["kode_invoice"];
             $find_invoice = sprintf("SINV-%s-%s-", $kode_invoice, ZiUtil::GetDateNow());
             $query = sprintf("id ILIKE '%s%s'", $find_invoice, '%');
             //var_dump($query);
             $condition = array('conditions' => $query, 'limit' => 1, 'offset' => 0, 'order' => 'id DESC');
             $last_kode_inv = SalesApotik::all($condition);
             //var_dump($last_kode_inv);
             if (is_null($last_kode_inv)) {
                 $last_kode_inv = "00000";
             }
             $SaleKodeGen = sprintf("SINV-%s-%s-%s", $kode_invoice, ZiUtil::GetDateNow(), str_pad((int) $last_kode_inv + 1, 5, "0", STR_PAD_LEFT));
             //var_dump($SaleKodeGen);
             $total_amount = 0;
             foreach ($rows as $row) {
                 $amount = $row["item_amount"];
                 $attr_detail = array("created" => date("Y-m-d H:i:s"), "parent" => $SaleKodeGen, "item_kode" => $row["item_kode"], "item_nama" => $row["item_nama"], "item_uom" => $row["item_uom"], "item_price" => $row["item_price"], "warehouse" => $row["from_warehouse"], "dosis" => $row["dosis"], "actual_qty" => $row["item_qty"], "basic_rate" => $row["basic_rate"], "batch_no" => $row["item_batch"], "amount" => $amount);
                 $voucher_detail_no = ZiUtil::GetNowID();
                 $attr_detail["id"] = $voucher_detail_no;
                 $tableDetail = DetailApotik::table();
                 $tableDetail->insert($attr_detail);
                 $attr_folio = array("fol_id" => $voucher_detail_no, "fol_jenis" => "T", "fol_nama" => $row["item_nama"], "fol_jumlah" => $row["item_qty"], "fol_nominal" => $amount, "fol_lunas" => "n", "fol_nominal_satuan" => $row["item_price"], "fol_waktu" => date("Y-m-d H:i:s"), "id_biaya" => $row["item_kode"], "id_biaya_tambahan" => 0, "id_cust_usr" => $post["cust_id"], "id_reg" => empty($post["reg_id"]) ? "" : $post["reg_id"]);
                 $table_folio = KlinikFolio::table();
                 $table_folio->insert($attr_folio);
                 // outgoing
                 if (isset($row["from_warehouse"]) && !empty($row["from_warehouse"])) {
                     $stock_queue = new ZiStockQueue();
                     $stock_queue->outgoing_stock($row["item_kode"], $row["from_warehouse"], $row["item_qty"], $row["item_batch"]);
                     $valuation_rate = ZiStockQueue::valuation_rate($row["item_kode"], $row["from_warehouse"], $row["item_batch"]);
                     $qty_after_trans = ZiUtil::check_int($row["actual_qty"]) - ZiUtil::check_int($row["item_qty"]);
                     $stock_value_diff = (0 - ZiUtil::check_int($row["item_qty"])) * $valuation_rate;
                     $stock_value = $qty_after_trans * $valuation_rate;
                     // $valuation_rate diperoleh dari total all incoming stock
                     // saat nya entry data stock ledger
                     $stockLedger = new ZiStockLedger();
                     $stockLedger->insert_db($row["item_kode"], "Sales Apotik", $SaleKodeGen, $voucher_detail_no, 0 - ZiUtil::check_int($row["item_qty"]), $row["from_warehouse"], $qty_after_trans, $valuation_rate, $stock_value, $stock_value_diff, 0, $row["item_batch"]);
                 }
                 $total_amount += $amount;
             }
             $attr_master = array("fiscal_year" => date('Y'), "company" => "RSMM", "posting_date" => date("Y-m-d H:i:s"), "posting_time" => date("H:i:s"), "created" => date("Y-m-d H:i:s"), "modified" => date("Y-m-d H:i:s"), "pasien_reg_no" => $post["reg_no"], "pasien_nama" => $post["pasien_nama"], "pasien_alamat" => $post["pasien_alamat"], "pasien_jenis" => $post["pasien_jenis"], "price_list" => $post["price_list"], "dokter" => $post["dokter"], "keterangan" => $post["keterangan"], "discount_rate" => 0, "kasir" => $post["kasir"], "payment" => $post["bayar_total"]);
             $attr_master["amount"] = $total_amount;
             $attr_master["id"] = $SaleKodeGen;
             $table = SalesApotik::table();
             $table->insert($attr_master);
             $dataset = array();
             $dataset["success"] = true;
             $dataset["kode_invoice"] = $SaleKodeGen;
             ZiUtil::to_json(json_encode($dataset));
             /*App::flash('info', 'Data Tersimpan.');
               App::redirect('selling.pos');*/
         }
     } catch (Exception $e) {
         // echo 'Caught exception: ', $e->getMessage(), "\n";
         header('HTTP/1.1 500 Internal Server Booboo');
         header('Content-Type: application/json; charset=UTF-8');
         die(json_encode(array('message' => $e->getMessage(), 'code' => 1337)));
     }
 }