public function genInvoice() { $kode_invoice = "070"; $find_invoice = sprintf("SINV-%s-%d-", $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-%d-%s", $kode_invoice, ZiUtil::GetDateNow(), str_pad((int) $last_kode_inv + 1, 5, "0", STR_PAD_LEFT)); var_dump($SaleKodeGen); }
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))); } }