fadlyshafa

Untitled

Jun 10th, 2020
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Purchase_return extends CI_Controller
  4. {
  5. function __construct() {
  6. parent::__construct();
  7. $this->load->model('purchase_return_model');
  8. $this->load->model('purchase_model');
  9. $this->load->model('company_setting_model');
  10. $this->load->model('warehouse_model');
  11. $this->load->model('kurs_model');
  12. $this->load->model('log_model');
  13. }
  14.  
  15. public function index(){
  16. //get purchase return to display list
  17. $data['data'] = $this->purchase_return_model->getPurchaseReturn();
  18. $this->load->view('purchase_return/list',$data);
  19. }
  20. /* call add view to add purchase return */
  21. public function add()
  22. {
  23.  
  24.  
  25. // $data['product'] = $this->purchase_model->getProduct();
  26. $id = $this->input->post('id');
  27. $data['warehouse'] = $this->purchase_return_model->getWarehouse($id);
  28. $data['supplier'] = $this->purchase_return_model->getSupplier();
  29. $data['reference_no'] = $this->purchase_return_model->getReferenceNo();
  30. // $data['reference_no'] = $this->purchase_return_model->createReferenceNo();
  31. // $data['service'] = $this->purchase_return_model->getService();
  32. $data['itemrequest'] = $this->warehouse_model->getItemRequestNo();
  33. $this->load->view('purchase_return/add',$data);
  34.  
  35. }
  36. /* get single product */
  37. public function getProduct($product_id,$warehouse_id){
  38. $data = $this->purchase_return_model->getProduct($product_id,$warehouse_id);
  39. $data['discount'] = $this->purchase_model->getDiscount();
  40. $data['tax'] = $this->purchase_model->getTax();
  41. echo json_encode($data);
  42. //print_r($data);
  43. }
  44. /* get all product warehouse wise */
  45. public function getProducts($warehouse_id){
  46. $data = $this->purchase_return_model->getProducts($warehouse_id);
  47. echo json_encode($data);
  48. //print_r($data);
  49. }
  50.  
  51.  
  52. public function getItemRequest($supplier_id) {
  53. $data = $this->warehouse_model->getItemRequestNo($supplier_id);
  54. echo json_encode($data);
  55. }
  56.  
  57.  
  58.  
  59. /* This function is used to search product code / name in database */
  60. public function getAutoCodeName($code,$search_option,$warehouse){
  61. //$code = strtolower($code);
  62. $p_code = $this->input->post('p_code');
  63. $p_search_option = $this->input->post('p_search_option');
  64. $data = $this->purchase_return_model->getProductCodeName($p_code,$p_search_option,$warehouse);
  65. if($search_option=="Code"){
  66. $list = "<ul class='auto-product'>";
  67. foreach ($data as $val){
  68. $list .= "<li value=".$val->code.">".$val->code."</li>";
  69. }
  70. $list .= "</ul>";
  71. }
  72. else{
  73. $list = "<ul class='auto-product'>";
  74. foreach ($data as $val){
  75. $list .= "<li value=".$val->product_id.">".$val->name."</li>";
  76. }
  77. $list .= "</ul>";
  78. }
  79.  
  80. echo $list;
  81. //echo json_encode($data);
  82. //print_r($list);
  83. }
  84. /* This function is used to add purchase return in database */
  85.  
  86.  
  87. public function addPurchaseReturn()
  88. {
  89.  
  90. $sql = "SELECT purchase_return_id FROM purchase_return_items ORDER BY purchase_return_id desc limit 1";
  91. $angka = $this->db->query($sql)->row();
  92.  
  93. $this->form_validation->set_rules('date','Date','trim|required');
  94. $this->form_validation->set_rules('reference_no','Reference No','trim|required');
  95. $this->form_validation->set_rules('supplier_id','Supplier ID','trim|required');
  96. $this->form_validation->set_rules('warehouse_id','Warehouse ID','trim|required');
  97. if($this->form_validation->run()==false){
  98.  
  99. $this->add();
  100. }
  101. else
  102. {
  103. $warehouse_id = $this->input->post('warehouse_id');
  104. $data = array(
  105. "date" => $this->input->post('date'),
  106. "reference_no" => $this->input->post('reference_no'),
  107. "purchase_return_id" => $angka->purchase_return_id + 1,
  108. "supplier_id" => $this->input->post('supplier_id'),
  109. "supplier_name" => $this->input->post('supplier_name'),
  110. "warehouse_id" => $this->input->post('warehouse_id'),
  111. "total" => $this->input->post('grand_total'),
  112. "discount_value" => $this->input->post('total_discount'),
  113. "tax_value" => $this->input->post('total_tax'),
  114. "note" => $this->input->post('note'),
  115. "user" => $this->session->userdata('user_id')
  116. );
  117.  
  118. if($this->purchase_return_model->addModel2($data))
  119. {
  120. foreach($_POST['items_id_for_purchase'] as $i => $si_id){
  121.  
  122. $product_qty = $_POST['items_qty_for_purchase'][$i];
  123. $qty = $_POST['items_qty_for_purchase'][$i];
  124. $idp = $_POST['product_id'][$i];
  125. $idi = $_POST['items_id_for_purchase'][$i];
  126.  
  127. $data5 = array(
  128. 'purchase_return_id' => $idi,
  129. 'product_id' => $idp,
  130. 'quantity' => $qty
  131. );
  132.  
  133. $this->db->insert('purchase_return_items', $data5);
  134.  
  135.  
  136. $idp = $this->db->select('*')
  137. ->from('product_grouping')
  138. ->where('product_id', $idp)
  139. ->get()
  140. ->result();
  141.  
  142. if ($idp) {
  143. $arlist = json_encode(unserialize($idp[0]->list));
  144. $arlist = json_decode($arlist);
  145.  
  146. for ($ilist = 0; $ilist < count($arlist); $ilist++) {
  147.  
  148. $quantity = $qty * $arlist[$ilist]->ql;
  149.  
  150. $this->db->set('quantity', 'quantity'+$quantity)
  151. ->where('product_id', $arlist[$ilist]->pl)
  152. ->update('products');
  153.  
  154. }
  155. }
  156.  
  157.  
  158. // echo "<pre>";
  159. // var_dump($data,$data5);
  160. // echo "</pre>";
  161. // exit;
  162.  
  163. }
  164.  
  165.  
  166. }
  167.  
  168. redirect('purchase_return','refresh');
  169. }
  170.  
  171. }
  172.  
  173.  
  174. /* This function is used to call view edit purchase return */
  175. // public function edit($id)
  176. // {
  177. // $kursdata = $this->company_setting_model->getCurrency();
  178.  
  179. // if(!$sock= @fsockopen("www.google.com", 80))
  180. // {
  181.  
  182. // }
  183. // else
  184. // {
  185.  
  186. // foreach($kursdata as $kursd)
  187. // {
  188. // // $currencyValue2 = $this->currencyConverter2($kursd->kurs,"IDR");
  189.  
  190. // $data2 = array(
  191. // "kurs" => $kursd->kurs,
  192. // // "nominal" => $currencyValue2
  193. // );
  194.  
  195. // $this->kurs_model->editModel($data2,$kursd->kurs_id);
  196. // }
  197. // }
  198.  
  199. // // $data['product'] = $this->purchase_model->getProduct();
  200. // $data['warehouse'] = $this->purchase_return_model->getWarehouse();
  201. // $data['supplier'] = $this->purchase_return_model->getSupplier();
  202. // $data['reference_no'] = $this->purchase_return_model->getReferenceNo();
  203. // // $data['reference_no'] = $this->purchase_return_model->createReferenceNo();
  204. // // $data['service'] = $this->purchase_return_model->getService();
  205.  
  206. // // $data['items'] = $this->purchase_return_model->getPurchaseReturnItems($data['data'][0]->id,$data['data'][0]->warehouse_id);
  207. // $this->load->view('purchase_return/edit',$data);
  208.  
  209. // }
  210.  
  211. public function edit($id){
  212. $this->load->library('form_validation');
  213.  
  214. $data['warehouse'] = $this->purchase_return_model->getWarehouse();
  215. $data['supplier'] = $this->purchase_return_model->getSupplier();
  216. $data['reference_no'] = $this->purchase_return_model->getReferenceNo();
  217. $data['data1'] = $this->purchase_return_model->productlistid($id);
  218. $data['data'] = $this->purchase_return_model->getData($id);
  219.  
  220. $this->form_validation->set_rules('date', 'Date', 'required');
  221. $this->form_validation->set_rules('reference_no', 'Reference No', 'required');
  222. $this->form_validation->set_rules('supplier_id', 'Supplier ID','required');
  223. $this->form_validation->set_rules('warehouse_id', 'Warehouse ID','required');
  224.  
  225. if($this->form_validation->run()){
  226. $params = array(
  227. 'date' => $this->input->post('date'),
  228. 'reference_no' => $this->input->post('reference_no'),
  229. 'supplier_id' => $this->input->post('supplier_id'),
  230. 'supplier_name' => $this->input->post('supplier_name'),
  231. 'warehouse_id' => $this->input->post('warehouse_id'),
  232. 'total' => $this->input->post('grand_total'),
  233. 'discount_value' => $this->input->post('total_discount'),
  234. 'tax_value' => $this->input->post('total_tax'),
  235. 'note' => $this->input->post('note'),
  236. 'user' => $this->input->post('user_id')
  237. );
  238.  
  239. $this->db->where('purchase_return_id', $id);
  240. $this->db->update('purchase_return', $params);
  241.  
  242. //$id = $this->db->insert_id();
  243.  
  244.  
  245. foreach($_POST['items_id_for_purchase'] as $i => $si_id){
  246.  
  247. $product_qty = $_POST['items_qty_for_purchase'][$i];
  248. $qty = $_POST['items_qty_for_purchase'][$i];
  249. $idp = $_POST['product_id'][$i];
  250. $idi = $_POST['items_id_for_purchase'][$i];
  251.  
  252. $params1 = array(
  253. 'product_id' => $idp,
  254. 'quantity' => $qty
  255. );
  256.  
  257. $purchase_return_id = $_POST['purchase_return_id'][$i];
  258.  
  259. $this->db->where('purchase_return_id', $id);
  260. $this->db->update('purchase_return_items', $params1);
  261. // echo "<pre>";
  262. // var_dump($params);
  263. // echo "</pre>";
  264. // exit;
  265. }
  266.  
  267. redirect('purchase_return');
  268. }
  269. else{
  270. $data['products'] = $this->db->get('products');
  271. $data['purchase_return'] = $this->db->get_where('purchase_return', array('purchase_return_id' => $id))->row();
  272. $data['item_request_items'] =
  273. $this->db->select('pi.purchase_item_id, pi.product_id, pi.quantity, pi.quantityreal, p.code, p.name')
  274. ->from('purchase_items pi')
  275. ->join('products p', 'pi.product_id=p.product_id' , 'left')
  276. ->where('pi.purchase_id', $id)
  277. ->get();
  278.  
  279.  
  280. $this->db->get_where('purchase_return_items', array('purchase_return_id' => $id));
  281.  
  282. // print_r(var_dump($this->db->last_query()));
  283.  
  284.  
  285.  
  286. $this->load->view('purchase_return/edit', $data);
  287. }
  288. }
  289.  
  290. // /* This function is used to delete discount record in databse */
  291. public function delete($id){
  292. if($this->purchase_return_model->deleteModel($id)){
  293. $log_data = array(
  294. 'user_id' => $this->session->userdata('user_id'),
  295. 'table_id' => $id,
  296. 'message' => 'Purchase Return Deleted'
  297. );
  298. $this->log_model->insert_log($log_data);
  299. redirect('purchase_return','return');
  300. }
  301. else{
  302. redirect('purchase_return','return');
  303. }
  304. }
  305. /* This function is to edit purchase return record in database */
  306.  
  307. // public function editPurchaseReturn()
  308. // {
  309. // $id = $this->input->post('id');
  310. // $this->form_validation->set_rules('date','Date','trim|required');
  311. // $this->form_validation->set_rules('reference_no','Reference No','trim|required');
  312. // $this->form_validation->set_rules('supplier_id','Supplier ID','trim|required');
  313. // $this->form_validation->set_rules('warehouse_id','Warehouse ID','trim|required');
  314. // if($this->form_validation->run()==false){
  315.  
  316. // $this->add();
  317. // }
  318. // else
  319. // {
  320. // $warehouse_id = $this->input->post('warehouse_id');
  321. // $data = array(
  322. // "date" => $this->input->post('date'),
  323. // "reference_no" => $this->input->post('reference_no'),
  324. // "supplier_id" => $this->input->post('supplier_id'),
  325. // "supplier_name" => $this->input->post('supplier_name'),
  326. // "warehouse_id" => $this->input->post('warehouse_id'),
  327. // "total" => $this->input->post('grand_total'),
  328. // "discount_value"=> $this->input->post('total_discount'),
  329. // "tax_value" => $this->input->post('total_tax'),
  330. // "note" => $this->input->post('note'),
  331. // "user" => $this->session->userdata('user_id')
  332. // );
  333.  
  334. // if($this->purchase_return_model->getAll($id,$data))
  335. // {
  336. // foreach($_POST['items_id_for_purchase'] as $i => $si_id){
  337.  
  338. // $product_qty = $_POST['items_qty_for_purchase'][$i];
  339. // $qty = $_POST['items_qty_for_purchase'][$i];
  340. // $idp = $_POST['product_id'][$i];
  341. // $idi = $_POST['items_id_for_purchase'][$i];
  342.  
  343. // $data5 = array(
  344. // 'purchase_return_id' => $idi,
  345. // 'product_id' => $idp,
  346. // 'quantity' => $qty
  347. // );
  348.  
  349. // $this->db->insert('purchase_return_items', $data5);
  350.  
  351.  
  352. // $idp = $this->db->select('*')
  353. // ->from('product_grouping')
  354. // ->where('product_id', $idp)
  355. // ->get()
  356. // ->result();
  357.  
  358. // if ($idp) {
  359. // $arlist = json_encode(unserialize($idp[0]->list));
  360. // $arlist = json_decode($arlist);
  361.  
  362. // for ($ilist = 0; $ilist < count($arlist); $ilist++) {
  363.  
  364. // $quantity = $qty * $arlist[$ilist]->ql;
  365.  
  366. // $this->db->set('quantity', 'quantity'+$quantity)
  367. // ->where('product_id', $arlist[$ilist]->pl)
  368. // ->update('products');
  369.  
  370. // }
  371. // }
  372.  
  373.  
  374. // //echo "<pre>";
  375. // // var_dump($data,$data5);
  376. // // echo "</pre>";
  377. // // exit;
  378.  
  379. // }
  380.  
  381.  
  382. // }
  383.  
  384. // redirect('purchase_return','refresh');
  385. // }
  386.  
  387. // }
  388.  
  389. function currencyConverter2($currency_from,$currency_to)
  390. {
  391. if($currency_from==$currency_to)
  392. {
  393. return 1;
  394. }
  395. else
  396. {
  397. //$currency_output = round(currency($currency_input, $currency_from,$currency_to, false),2);
  398. //$currency_input=substr($currency_input, 0, -3);
  399. $currency_input=filter_var(1, FILTER_SANITIZE_NUMBER_INT);
  400. $from_Currency = urlencode($currency_from);
  401. $to_Currency = urlencode($currency_to);
  402. $get = file_get_contents("https://finance.google.com/finance/converter?a=1&from=$from_Currency&to=$to_Currency");
  403. $get = explode("<span class=bld>",$get);
  404. $get = explode("</span>",@$get[1]);
  405. $converted_currency = preg_replace("/[^0-9\.]/", null, @$get[0]);
  406. $converted_currency = $converted_currency;
  407. return $converted_currency;
  408.  
  409. //return $currency_output;
  410. }
  411. }
  412.  
  413. public function addshipp()
  414. {
  415. $data['po']= $this->purchase_return_model->getPurchaseSetujui();
  416. $this->load->view('purchase_return/add',$data);
  417. }
  418.  
  419. public function getSupplier($supplier_id) {
  420. $data['data'] = $this->purchase_return_model->getSupplier($supplier_id);
  421. echo json_encode($data);
  422. }
  423.  
  424. public function getReferenceNo($reference_no) {
  425. $data = $this->purchase_return_model->getReferenceNo($reference_no);
  426. echo json_encode($data);
  427. }
  428.  
  429. public function get_product(){
  430. $id = $this->input->post('id');
  431.  
  432. $products = $this->db->get_where('products', array('product_id' => $id));
  433.  
  434. if($products->num_rows() > 0){
  435. echo '<tr>';
  436. echo '<td><input type="hidden" name="items_product_id[]" value="' . $products->row()->product_id . '"><a class="delete"><img src="' . base_url("assets/images/bin3.png") . '"></a></td>';
  437. echo '<td>' . $products->row()->code . '</td>';
  438. echo '<td>' . $products->row()->name . '</td>';
  439. echo '<td>' . $products->row()->unit . '</td>';
  440. echo '<td><input type="hidden" class="column-price" value="' . $products->row()->price . '" name="items_price[]">' . $products->row()->price . '</td>';
  441. echo '<td><input class="column-quantity form-control" style="width:100px" type="number" name="items_quantity[]" value="0"></td>';
  442. echo '<td class="column-total">0</td>';
  443. echo '</tr>';
  444. }
  445. }
  446.  
  447. public function getDetail(){
  448. $id = $this->input->post('id');
  449.  
  450. $data = $this->db->select('pi.*,pi.purchase_item_id, pi.product_id, pi.quantity, pi.quantityreal, p.code, p.name')
  451. ->from('purchase_items pi')
  452. ->join('products p', 'pi.product_id=p.product_id' , 'left')
  453. ->where('pi.purchase_id', $id)
  454. ->get()
  455. ->result();
  456. $i=0;
  457.  
  458. echo '<table class="table table-condensed table-border">';
  459. echo '<thead>';
  460. echo '<tr>';
  461. echo '<th></th>';
  462. echo '<th>Code</th>';
  463. echo '<th>Product Description</th>';
  464. // echo '<th>HSN/SAC Code</th>';
  465. echo '<th>Quantity</th>';
  466. echo '<th>Returned Quantity</th>';
  467. echo '<th>Price</th>';
  468. echo '<th>Unit</th>';
  469. echo '<th>Sub Total</th>';
  470. echo '<th>Total</th>';
  471. echo '</tr>';
  472. echo '<thead>';
  473. echo '<tbody>';
  474. foreach($data as $row){
  475. echo '<tr>';
  476.  
  477. echo '<td><input type="checkbox" name="items_id_for_purchase[' . $i . ']" value="' . $row->purchase_item_id . '"></td>';
  478. echo '<td>' . $row->code . '</td>';
  479. echo '<td>' . $row->name . '</td>';
  480. echo '<td>' . ($row->quantity - $row->quantityreal) . '</td>';
  481. echo '<td><input type="hidden" name="product_id[' . $i . ']" value="' . $row->product_id . '"><input type="number" class="form-control" style="width:100px" value="0" name="items_qty_for_purchase[' . $i . ']" max="' . ($row->quantity - $row->quantityreal) . '"></td>';
  482.  
  483. echo '<td>' . $row->price . '</td>';
  484. echo '<tr>';
  485.  
  486. $i++;
  487. }
  488. echo '</tbody>';
  489. echo '</table>';
  490.  
  491. }
  492.  
  493. }
  494. ?>
RAW Paste Data