����JFIF��H�H����Exif��MM�*���� ��3����V�����3������3�(��������������������3�����
Server IP : 74.208.127.88 / Your IP : 3.140.201.179 Web Server : Apache/2.4.41 (Ubuntu) System : Linux ubuntu 5.4.0-163-generic #180-Ubuntu SMP Tue Sep 5 13:21:23 UTC 2023 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/goldencar/sae/application/model/ |
Upload File : |
<?php date_default_timezone_set("America/Mexico_City"); class pos extends dbconn { public function __construct() { $this->initDBO(); } /***************************************************************** start box **************************************************************&*****/ //select box public function getBox_open(){ $db = $this->dblocal; //SELECT * FROM `box opening` WHERE DATE(`created_at`) <= CURDATE() OR TIME(`created_at`) <= "23:59:59"; try { $stmt = $db->prepare("SELECT *,cash as fondo FROM `box opening` WHERE DATE(`created_at`) = CURDATE() and TIME(`created_at`) <= '23:59:59' and box_id is null"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //guardar box //INSERT INTO `box opening` (`id`, `stock_id`, `cash`, `user_id`, `status`, `created_at`) VALUES ('1', '1', '250', '9', '1', '2023-05-29 00:14:33.000000'); public function new_openingBox($stock,$cash,$user_id,$status,$created_at) { $db = $this->dblocal; try { $kind=2; $stmt = $db->prepare("INSERT INTO `box opening`(`stock_id`, `cash`, `user_id`, `status`, `created_at`) values (:stock_id, :cash, :user_id, :status, :created_at)"); $stmt->bindParam("stock_id",$stock); $stmt->bindParam("cash",$cash); $stmt->bindParam("user_id",$user_id); $stmt->bindParam("status",$status); $stmt->bindParam("created_at", $created_at); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save box"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //entradas y salidas de dinero //INSERT INTO `saving` (`id`, `concept`, `amount`, `date_at`, `kind`, `box_id`, `created_at`) //VALUES ('1', 'PAGO CFE', NULL, '540', NULL, '1', NULL, '2023-05-29 07:30:15.000000'); public function new_InOut($concept,$amount,$kind,$user_id,$stock_id,$created_at) { $db = $this->dblocal; try { $stmt = $db->prepare("INSERT INTO `saving`(`concept`, `amount`, `kind`,`user_id`, `stock_id`, `created_at`) values (:concept, :amount, :kind,:user_id, :stock_id, :created_at)"); $stmt->bindParam("concept",$concept); $stmt->bindParam("amount",$amount); $stmt->bindParam("kind",$kind); $stmt->bindParam("user_id",$user_id); $stmt->bindParam("stock_id",$stock_id); $stmt->bindParam("created_at", $created_at); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save mov In/Out"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //id maximo de entradas salidas de dinero public function folio_inout(){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT MAX(id) AS id from `saving` "); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //saldos de entradas public function get_TranInDay($awal,$akhir) { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT SUM(`amount`) as suma,created_at,`kind`,`stock_id`,id FROM `saving` WHERE `kind` = 1 and date(created_at) = CURDATE() GROUP BY kind" ); $stmt->bindParam("awal",$awal); $stmt->bindParam("akhir",$akhir); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //saldos de entradas public function get_TranOutDay($awal,$akhir) { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT SUM(`amount`) as suma,created_at,`kind`,`stock_id` FROM `saving` WHERE `kind` = 2 and (`created_at` BETWEEN :awal AND :akhir) GROUP BY kind" ); $stmt->bindParam("awal",$awal); $stmt->bindParam("akhir",$akhir); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //saldos de devoluciones public function getTransDev() { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT *, SUM(`price`) AS suma FROM `spend` WHERE date(`created_at`) = CURDATE() GROUP BY `id_seller`;" ); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //SELECT *,abs(SUM(`val`)) AS suma FROM `payment` WHERE date(`created_at`) = CURDATE(); public function getTransPay() { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT *,abs(SUM(`val`)) AS suma FROM `payment` WHERE date(`created_at`) = CURDATE();" ); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //registro por id //getInOutId public function getInOutId($id){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from saving where id = :id "); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /****************************************************************************** START TABEL person *******************************************************************************/ public function autoCompleteC($term) { $trm = "%".$term."%"; $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.* FROM customer a WHERE name like :term order by name asc"); $stmt->bindParam("term",$trm); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /****************************************************************************** START TABEL stock *******************************************************************************/ public function getStockId($id){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from stock where id = :id "); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /****************************************************************************** end TABEL stock *******************************************************************************/ /****************************************************************************** START TABEL m_item *******************************************************************************/ public function getAllItem($category) { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT @rownum := @rownum + 1 AS urutan,t.* FROM product t, (SELECT @rownum := 0) r WHERE category_id = :category ORDER BY id ASC"); $stmt->bindParam("category",$category); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //REPORTE DE inventario con urutan public function getListItem() { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT @rownum := @rownum + 1 AS urutan,t.* FROM m_item t, (SELECT @rownum := 0) r ORDER BY item_name ASC"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //REPORTE DE inventario con id public function getListItemID() { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT @rownum := @rownum + 1 AS id,t.* FROM m_item t, (SELECT @rownum := 0) r ORDER BY item_name ASC"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //inventario de tabla stock public function getAllstock() { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT * FROM `stocks` ORDER BY id ASC"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /* SELECT a.* ,c.`username` FROM t_sale a INNER JOIN m_user c ON a.`id_user` = c.`id_user` where a.sale_id = :id */ public function getItem($id_item){ $db = $this->dblocal; try { $stmt = $db->prepare("select a.*, c.is_service , c.product_children, c.qy from m_item a JOIN product c ON a.`barcode` = c.`barcode` WHERE a.`id_item` = :id"); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //BUSCAMOS PRODUCTO EN OPCION MAS DE UNA PIEZA public function getItem3($id_item){ $db = $this->dblocal; try { $stmt = $db->prepare("select a.*, c.is_service , c.product_children, c.qy,e.description from m_item a, product e JOIN product c ON a.`barcode` = c.`barcode` WHERE a.`barcode` = :id and status is null"); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //BUSCAMOS PRODUCTO EN OPCION MAS DE UNA PIEZA public function getItem_BAR($id_item){ $db = $this->dblocal; try { //select a.*, c.is_service , c.product_children, c.qy,e.description from m_item a, product e // JOIN product c ON a.`barcode` = c.`barcode` WHERE a.`barcode` = :id OR and status is null //SELECT p.* , c.* FROM `product` p, m_item c WHERE (p.`barcode` = '112233' OR `description` = '112233') and status is null $stmt = $db->prepare("SELECT * FROM m_item WHERE `barcode` = :id and status is null "); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //BUSCAMOS PRODUCTO EN OPCION MAS DE UNA PIEZA public function getItem_ALT($id_item){ $db = $this->dblocal; try { //select a.*, c.is_service , c.product_children, c.qy,e.description from m_item a, product e // JOIN product c ON a.`barcode` = c.`barcode` WHERE a.`barcode` = :id OR and status is null //SELECT p.* , c.* FROM `product` p, m_item c WHERE (p.`barcode` = '112233' OR `description` = '112233') and status is null $stmt = $db->prepare("SELECT * FROM m_item WHERE `alterno` = :id and status is null "); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //obtener registro de tabla m_item por codigo de barras public function getBarcode($id_item){ $db = $this->dblocal; try { $stmt = $db->prepare("select a.*, c.is_service , c.product_children, c.qy from m_item a JOIN product c ON a.`barcode` = c.`barcode` WHERE a.`barcode` = :id and status is null"); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getIdProduct($barcode){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT id,name,barcode,image,product_children,price_in,qy FROM product WHERE barcode= :barcode"); $stmt->bindParam("barcode",$barcode); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getItemCompras($id_item){ $db = $this->dblocal; try { $stmt = $db->prepare("select sum(q) as compras from operation2 where product_id = :id and operation_type_id = 1"); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getItemCompras2($id_item){ $db = $this->dblocal; try { $stmt = $db->prepare("select sum(q) as Ocompras from operation2 where barcode = :barcode and operation_type_id = 1"); $stmt->bindParam("barcode",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getItemMerma($id_item){ $db = $this->dblocal; try { $stmt = $db->prepare("select sum(q) as merma from operation2 where product_id = :id and operation_type_id = 2"); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //ventas por producto public function getItemVentas($barcode){ $db = $this->dblocal; try { $stmt = $db->prepare("select sum(qty) as ventas from t_sale_detail where barcode = :id and is_draft = 0"); $stmt->bindParam("id",$barcode); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //ventas por turno public function getVentasBox(){ $db = $this->dblocal; try { $stmt = $db->prepare("select sum(total) as ventas from sell where box_id is null"); $stmt->bindParam("id",$barcode); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //ventas por dealle public function getTotalSellId($sale_id){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT sum(`qty`*`price`) as totalSell FROM `t_sale_detail` WHERE `sale_id` = :sale_id"); $stmt->bindParam("sale_id",$sale_id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //entradas por turno public function getEntradasBox(){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT sum(`amount`) as entradas FROM `saving` WHERE `kind` = 1 and `box_id` is null"); $stmt->bindParam("id",$barcode); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //salidas por turno public function getSalidasBox(){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT sum(`amount`) as salidas FROM `saving` WHERE `kind` = 2 and `box_id` is null"); $stmt->bindParam("id",$barcode); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getItemDev($id){ $db = $this->dblocal; try { $stmt = $db->prepare("select sum(q) as dev from operation where product_id = :id and operation_type_id = 5"); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getClientMostrador($item){ $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from customer a where a.name = :name "); $stmt->bindParam("name",$item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //sleeccionar cliente por rfc public function getClientByRFC($client_rfc){ $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from customer a where a.rfc = :client_rfc "); $stmt->bindParam("client_rfc",$client_rfc); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getClient($id_cust){ $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from customer a where a.id_cust = :id_cust "); $stmt->bindParam("id_cust",$id_cust); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //guardar cliente public function new_customer($name,$country,$phone,$gender) { $db = $this->dblocal; try { $kind=2; $stmt = $db->prepare("insert into customer(name,country,phone,gender,kind) values (:name,:country,:phone,:gender,:kind)"); $stmt->bindParam("name",$name); $stmt->bindParam("country",$country); $stmt->bindParam("phone",$phone); $stmt->bindParam("gender",$gender); $stmt->bindParam("kind", $kind); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save customer"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //obtener el ultimo registro de compras public function getRe(){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT MAX(id) AS id FROM re"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //obtener el ultimo registro de compras public function getRes(){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT c.`product_id`,c.`barcode`,p.`barcode`,p.item_name,p.stock,p.price FROM `operation2` c INNER JOIN m_item p on c.`barcode` = p.`barcode` WHERE c.`product_id` IS NULL GROUP BY p.barcode"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getItemPrice($id_item){ $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from listprice a where a.barcode = :id "); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getItem2($id_item){ $db = $this->dblocal; try { $stmt =$db->prepare("SELECT COUNT(*) as contador FROM m_item where stock < :id"); $stmt->bindParam("id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateItem($iditem,$item_name,$price,$unit,$stock,$tax,$note) { $db = $this->dblocal; try { $stmt = $db->prepare("UPDATE m_item SET item_name = UPPER(:item_name), unit= :unit, stock= :stock, tax= :tax, price= :price, note= :note WHERE id_item= :iditem;"); $stmt->bindParam("iditem",$iditem); $stmt->bindParam("item_name",$item_name); $stmt->bindParam("price",$price); $stmt->bindParam("note",$note); $stmt->bindParam("unit",$unit); $stmt->bindParam("stock",$stock); $stmt->bindParam("tax",$tax); $stmt->execute(); $stat[0] = true; $stat[1] = "Actualizado!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //noviembre/2021 ($barcode,$item_name,$unit,$stock,$price,$note ,$tax) public function saveItem($barcode,$item_name,$unit,$stock,$price,$note ,$tax){ $db = $this->dblocal; try { $stmt = $db->prepare("call saveItem(:barcode,:item_name,:unit,:stock ,:price,:note,:tax)"); $stmt->bindParam("barcode",$barcode); $stmt->bindParam("item_name",$item_name); $stmt->bindParam("price",$price); $stmt->bindParam("unit",$unit); $stmt->bindParam("stock",$stock); $stmt->bindParam("note",$note); $stmt->bindParam("tax",$tax); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function deleteItem($iditem) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from m_item where id_item = :id"); $stmt->bindParam("id",$iditem); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //autocompletar por nombre o codigo public function autoCompleteItem($term) { $trm = "%".$term."%"; $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.* FROM m_item a WHERE ( item_name like :term or barcode like :term ) and status is NULL order by item_name asc limit 10"); $stmt->bindParam("term",$trm); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //autocompletar folio de venta o trans public function autoCompleteSell($term) { $trm = "%".$term."%"; $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.* FROM sell a WHERE ( id like :term or sale_id like :term ) and is_draft = 0 order by id asc"); $stmt->bindParam("term",$trm); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //autocompletar por nombre o codigo CON EXITENCIAS public function autoCompleteItemINV($term) { $trm = "%".$term."%"; $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.* FROM m_item a WHERE ( item_name like :term or barcode like :term ) and status is NULL and stock > 0 order by item_name asc"); $stmt->bindParam("term",$trm); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /******************************************************************************* END OF TABEL M_Item *******************************************************************************/ /****************************************************************************** START TABEL Product actualizacion 20/04/2021 *******************************************************************************/ public function saveProduct($barcode,$item_name,$price,$unit,$stock,$note){ $db = $this->dblocal; try { $stmt = $db->prepare("call saveItem(:barcode,:item_name,:unit,:stock,:price,:note)"); $stmt->bindParam("barcode",$barcode); $stmt->bindParam("item_name",$item_name); $stmt->bindParam("price",$price); $stmt->bindParam("note",$note); $stmt->bindParam("unit",$unit); $stmt->bindParam("stock",$stock); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /******************************************************************************* END OF TABEL Product *******************************************************************************/ /******************************************************************************* START OF TABEL promotion *******************************************************************************/ public function getPromo($id_item){ $db = $this->dblocal; try { $stmt =$db->prepare("select a.* from promotion a where a.product_id = :product_id "); $stmt->bindParam("product_id",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /****************************************************************************** END OF TABEL promotion *******************************************************************************/ /****************************************************************************** TABEL T_JUAL AND TEMP_JUAL *******************************************************************************/ public function deleteTempSaleByUser($iduser) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from temp_sale where id_user = :id"); $stmt->bindParam("id",$iduser); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //eliminamos sell temp DELETE FROM `sell_M` WHERE `uniqid` = '64a5e1ffcc931' public function deleteSellTempByUniqid($uniqid) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from temp_sell where uniqid = :id"); $stmt->bindParam("id",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //ELIMINAMOS registros al timbrar de la tabla public function resetTempSaleByUserSession($iduser,$uniqid) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from temp_sale where id_user = :id and uniqid = :uniqid"); $stmt->bindParam("id",$iduser); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function resetTempSaleByUserSessionOC($iduser,$uniqid) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from purchase_order where id_user = :id and uniqid != :uniqid"); $stmt->bindParam("id",$iduser); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //agregar registros de tempSEll public function getListSellTemp($uniqid){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT @rownum := @rownum + 1 AS urutan,t.* FROM temp_sell t, (SELECT @rownum := 0) r where t.uniqid= :uniqid ORDER BY input_date DESC"); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getListTempSale($cashier,$uniqid){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT @rownum := @rownum + 1 AS urutan,t.* FROM temp_sale t, (SELECT @rownum := 0) r where t.id_user= :cashier and t.uniqid= :uniqid ORDER BY input_date DESC"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getListTempSale2($cashier,$uniqid){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT @rownum := @rownum + 1 AS urutan,t.* FROM temp_exist t, (SELECT @rownum := 0) r where t.id_user= :cashier and t.uniqid= :uniqid ORDER BY input_date DESC"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getListTempSale4($cashier,$uniqid){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT @rownum := @rownum + 1 AS urutan,t.* FROM purchase_order t, (SELECT @rownum := 0) r where t.id_user = :cashier and t.uniqid != :uniqid ORDER BY input_date DESC"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function deleteSellTemp($uniqid,$id_item) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from temp_sell where uniqid = :uniqid and id = :id_item "); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete sell id!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //eliminar registro de temp_sale public function deleteTempSaleProduct($cashier,$uniqid,$id_item) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from temp_sale where id_user = :id and uniqid = :uniqid and id_item = :id_item "); $stmt->bindParam("id",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function deleteTempSaleProduct2($cashier,$uniqid,$id_item) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from temp_exist where id_user = :id and uniqid = :uniqid and id_item = :id_item "); $stmt->bindParam("id",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function deleteTempSaleProduct4($cashier,$uniqid,$id_item) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from purchase_order where id_user = :id and uniqid = :uniqid and id_item = :id_item "); $stmt->bindParam("id",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateTempSale($cashier,$uniqid,$id_item) { $db = $this->dblocal; try { $stmt = $db->prepare("update temp_sale set qty=qty+1 where uniqid= :uniqid and id_user = :cashier and id_item = :id_item "); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //actualizar a ceros todo el inventario tabla m_item valores de stok negativos public function update_zeros() { $db = $this->dblocal; try { $stmt = $db->prepare("UPDATE `m_item` SET `stock` = '0' WHERE `m_item`.`stock` < 0 "); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit a zeros!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //actualizar a ceros todo el inventario tabla m_item valores de stok positivos public function update_zeros_pos() { $db = $this->dblocal; try { $stmt = $db->prepare("UPDATE `m_item` SET `stock` = '0' WHERE `m_item`.`stock` > 0 "); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit a zeros!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateTempSale4($cashier,$uniqid,$id_item) { $db = $this->dblocal; try { $stmt = $db->prepare("update purchase_order set qty=qty+1 where uniqid= :uniqid and id_user = :cashier and id_item = :id_item "); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateTempSaleHargaSale($cashier,$uniqid,$id_item,$value) { $db = $this->dblocal; try { $stmt = $db->prepare("update temp_sale set price = :value where uniqid= :uniqid and id_user = :cashier and id_item = :id_item "); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("value",$value); $stmt->execute(); $stat[0] = true; $stat[1] = "cambio exitoso!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateTempSaleHargaSale4($cashier,$uniqid,$id_item,$value) { $db = $this->dblocal; try { $stmt = $db->prepare("update purchase_order set price = :value where uniqid= :uniqid and id_user = :cashier and id_item = :id_item "); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("value",$value); $stmt->execute(); $stat[0] = true; $stat[1] = "cambio exitoso!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateTempSaleQty($cashier,$uniqid,$id_item ,$value) { $db = $this->dblocal; try { $stmt = $db->prepare("update temp_sale set qty= :value where uniqid= :uniqid and id_user = :cashier and id_item = :id_item "); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("value",$value); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateTempSaleQty4($cashier,$uniqid,$id_item ,$value) { $db = $this->dblocal; try { $stmt = $db->prepare("update purchase_order set qty= :value where uniqid= :uniqid and id_user = :cashier and id_item = :id_item "); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("value",$value); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function deleteSale($sale_id,$note) { $db = $this->dblocal; try { $stmt = $db->prepare("call deleteSale(:id,:note)"); $stmt->bindParam("id",$sale_id); $stmt->bindParam("note",$note); $stmt->execute(); $stat[0] = true; $stat[1] = 'Success Cancel'; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateTempSaleDisc($cashier,$uniqid,$id_item,$value) { $db = $this->dblocal; try { $stmt = $db->prepare("update temp_sale set discprc = :value where uniqid= :uniqid and id_user = :cashier and id_item = :id_item "); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("value",$value); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateTempSaleDisc4($cashier,$uniqid,$id_item,$value) { $db = $this->dblocal; try { $stmt = $db->prepare("update purchase_order set discprc = :value where uniqid= :uniqid and id_user = :cashier and id_item = :id_item "); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("value",$value); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //insertar registro en temp sell public function saveTempSell($uniqid,$sell_id,$sale_id,$person_id,$seller_id,$stock_id, $total, $qty) { $db = $this->dblocal; try { $stmt = $db->prepare("insert into temp_sell(uniqid, sell_id, sale_id, person_id, seller_id, stock_id, total, qty) values ( :uniqid , :sell_id, :sale_id, :person_id, :seller_id, :stock_id, :total, :qty)"); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("sell_id",$sell_id); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("person_id",$person_id); $stmt->bindParam("seller_id",$seller_id); $stmt->bindParam("stock_id",$stock_id); $stmt->bindParam("total",$total); $stmt->bindParam("qty",$qty); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveTempSale($cashier,$uniqid, $image,$id_item,$barcode,$unit,$item_name,$qty,$price,$discprn,$discrp) { $db = $this->dblocal; try { $stmt = $db->prepare("insert into temp_sale(id_user, uniqid, image, id_item, barcode, item_name, qty, unit, price, discprc, discrp) values (:cashier , :uniqid , :image, :id_item, :barcode, :item_name, :qty, :unit, :price, :discprn, :discrp)"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("image",$image); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("barcode",$barcode); $stmt->bindParam("unit",$unit); $stmt->bindParam("item_name",$item_name); $stmt->bindParam("qty",$qty); $stmt->bindParam("price",$price); $stmt->bindParam("discprn",$discprn); $stmt->bindParam("discrp",$discrp); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveTempSale4($cashier,$uniqid,$id_item,$barcode,$unit,$item_name,$qty,$price,$discprn,$discrp) { $db = $this->dblocal; try { $stmt = $db->prepare("insert into purchase_order(id_user, uniqid, id_item, barcode, item_name, qty, unit, price, discprc, discrp) values (:cashier , :uniqid , :id_item, :barcode, :item_name, :qty, :unit, :price, :discprn, :discrp)"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("barcode",$barcode); $stmt->bindParam("unit",$unit); $stmt->bindParam("item_name",$item_name); $stmt->bindParam("qty",$qty); $stmt->bindParam("price",$price); $stmt->bindParam("discprn",$discprn); $stmt->bindParam("discrp",$discrp); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } // saveTempSale2($kasir,$uniqid,$result['id_item'],$result['barcode'],$result['unit'],$result['item_name'],$result['qty'], $result['price'], $result['discprcn'],$result['discrp']); public function saveTempSale2($cashier,$uniqid, $image,$id_item,$barcode,$unit,$item_name,$qty,$price,$discprn,$discrp) { $db = $this->dblocal; try { $stmt = $db->prepare("insert into temp_sale(id_user, uniqid, image, id_item, barcode, item_name, qty, unit, price, discprc, discrp) values (:cashier , :uniqid , :image, :id_item, :barcode, :item_name, :qty, :unit, :price, :discprn, :discrp)"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("image",$image); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("barcode",$barcode); $stmt->bindParam("unit",$unit); $stmt->bindParam("item_name",$item_name); $stmt->bindParam("qty",$qty); $stmt->bindParam("price",$price); $stmt->bindParam("discprn",$discprn); $stmt->bindParam("discrp",$discrp); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveTempSaleS($cashier,$uniqid,$id_item,$barcode,$unit,$item_name,$qty,$price,$discprn,$discrp,$qy) { $db = $this->dblocal; try { $stmt = $db->prepare("insert into temp_sale(id_user, uniqid, id_item, barcode, item_name, qty, unit, price, discprc, discrp,qy) values (:cashier , :uniqid , :id_item, :barcode, :item_name, :qty, :unit, :price, :discprn, :discrp, :qy)"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("barcode",$barcode); $stmt->bindParam("unit",$unit); $stmt->bindParam("item_name",$item_name); $stmt->bindParam("qty",$qty); $stmt->bindParam("price",$price); $stmt->bindParam("discprn",$discprn); $stmt->bindParam("discrp",$discrp); $stmt->bindParam("qy",$qy); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveTempSaleE($cashier,$uniqid,$id_item,$barcode,$item_name,$price,$compras,$ventas,$dev,$ajustes,$existencia) { //$cashier,$uniqid,$result['id_item'],$result['barcode'],$result['item_name'],20.00,10.00, $result['price'], 11.00,12.00 $db = $this->dblocal; try { $stmt = $db->prepare("insert into temp_exist(id_user, uniqid, id_item, barcode, item_name,price, compras, ventas, dev, ajustes, existencia) values (:cashier , :uniqid , :id_item, :barcode, :item_name, :price, :compras, :ventas, :dev, :ajustes, :existencia)"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->bindParam("barcode",$barcode); $stmt->bindParam("item_name",$item_name); $stmt->bindParam("price",$price); $stmt->bindParam("compras",$compras); $stmt->bindParam("ventas",$ventas); $stmt->bindParam("dev",$dev); $stmt->bindParam("ajustes",$ajustes); $stmt->bindParam("existencia",$existencia); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //guardar apartado // saveSale($sale_id,$sale_date,$total,$id_client,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$credit_amount);// public function saveSale1($sale_id,$sale_date,$total,$id_client,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$credit_amount) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSale1( :sale_id, :sale_date, :total, :id_client, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :credit_amount)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("id_client",$id_client); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("credit_amount",$credit_amount); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //venta en efectivo //$insert = $pos->saveSale($sale_id, $sale_date,$total,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$f_pago1,$f_pago2,$id_seller,$person_id); public function saveSale($sale_id,$sale_date,$total,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$f_pago1,$f_pago2,$id_seller,$person_id) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSale( :sale_id, :sale_date, :total, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :f_pago1, :f_pago2, :id_seller, :person_id)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("f_pago1",$f_pago1); $stmt->bindParam("f_pago2",$f_pago2); $stmt->bindParam("id_seller",$id_seller); $stmt->bindParam("person_id",$person_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveSaleFac($sale_id,$sale_date,$total,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$f_pago1,$f_pago2,$id_seller,$person_id) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSaleFac( :sale_id, :sale_date, :total, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :f_pago1, :f_pago2, :id_seller, :person_id)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("f_pago1",$f_pago1); $stmt->bindParam("f_pago2",$f_pago2); $stmt->bindParam("id_seller",$id_seller); $stmt->bindParam("person_id",$person_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveSaleStock2($sale_id,$sale_date,$total,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$f_pago1,$f_pago2,$id_seller,$person_id) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSaleStock2( :sale_id, :sale_date, :total, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :f_pago1, :f_pago2, :id_seller, :person_id)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("f_pago1",$f_pago1); $stmt->bindParam("f_pago2",$f_pago2); $stmt->bindParam("id_seller",$id_seller); $stmt->bindParam("person_id",$person_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveSaleStock3($sale_id,$sale_date,$total,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$f_pago1,$f_pago2,$id_seller,$person_id) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSaleStock3( :sale_id, :sale_date, :total, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :f_pago1, :f_pago2, :id_seller, :person_id)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("f_pago1",$f_pago1); $stmt->bindParam("f_pago2",$f_pago2); $stmt->bindParam("id_seller",$id_seller); $stmt->bindParam("person_id",$person_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveSaleStock4($sale_id,$sale_date,$total,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$f_pago1,$f_pago2,$id_seller,$person_id) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSaleStock4( :sale_id, :sale_date, :total, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :f_pago1, :f_pago2, :id_seller, :person_id)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("f_pago1",$f_pago1); $stmt->bindParam("f_pago2",$f_pago2); $stmt->bindParam("id_seller",$id_seller); $stmt->bindParam("person_id",$person_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveSaleS($sale_id,$sale_date,$total,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$f_pago1,$f_pago2,$id_seller,$person_id,$stock_id) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSaleS( :sale_id, :sale_date, :total, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :f_pago1, :f_pago2, :id_seller, :person_id, :stock_id)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("f_pago1",$f_pago1); $stmt->bindParam("f_pago2",$f_pago2); $stmt->bindParam("id_seller",$id_seller); $stmt->bindParam("person_id",$person_id); $stmt->bindParam("stock_id",$stock_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //ventas a credito //saveSale2($sale_id,$sale_date,$total,$id_client,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$credit_amount) public function saveSale2($sale_id,$sale_date,$total,$id_client,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$credit_amount) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSale2( :sale_id, :sale_date, :total, :id_client, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :credit_amount)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("id_client",$id_client); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("credit_amount",$credit_amount); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveSale3($sale_id,$sale_date,$total,$id_client,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$credit_amount) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSale3( :sale_id, :sale_date, :total, :id_client, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :credit_amount)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("id_client",$id_client); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("credit_amount",$credit_amount); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveSale4($sale_id,$sale_date,$total,$id_client,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$credit_amount) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSale4( :sale_id, :sale_date, :total, :id_client, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :credit_amount)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("id_client",$id_client); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("credit_amount",$credit_amount); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveSale5($sale_id,$sale_date,$total,$id_client,$paid,$disc_prcn,$disc_rp,$uniqid,$id_user,$note,$credit_amount) { $db = $this->dblocal; try { $stmt = $db->prepare("call saveSale5( :sale_id, :sale_date, :total, :id_client, :paid, :disc_prcn, :disc_rp, :uniqid, :id_user, :note, :credit_amount)"); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("sale_date",$sale_date); $stmt->bindParam("total",$total); $stmt->bindParam("id_client",$id_client); $stmt->bindParam("paid",$paid); $stmt->bindParam("disc_prcn",$disc_prcn); $stmt->bindParam("disc_rp",$disc_rp); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("note",$note); $stmt->bindParam("credit_amount",$credit_amount); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; $stat[2] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //revisar registros en temp_sell getSubTotalSellTemp public function getSubTotalSellTemp($uniqid){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT SUM(total)AS total FROM temp_sell where uniqid= :uniqid "); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchColumn(0); $stat[2] = $stmt->rowCount(); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //revisar registros en temp_sale public function getSubTotalTempSale($cashier,$uniqid){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT SUM((price - (price*(discprc/100)))*qty)AS total FROM temp_sale where uniqid= :uniqid and id_user = :cashier"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchColumn(0); $stat[2] = $stmt->rowCount(); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getSubTotalTempSaleOC($cashier,$uniqid){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT SUM(price*qty)AS total FROM purchase_order where uniqid != :uniqid and id_user = :cashier"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchColumn(0); $stat[2] = $stmt->rowCount(); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function checkTempSale($cashier,$uniqid){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT id_user,uniqid FROM temp_sale where uniqid= :uniqid and id_user = :cashier"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->rowCount(); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getCheckProduk($cashier,$uniqid,$id_item ){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from temp_sale where uniqid= :uniqid and id_user = :cashier and id_item = :id_item"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->rowCount(); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getStockProduk($kasir,$uniqid,$id_item){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from temp_sale where uniqid= :uniqid and id_user = :kasir and id_item = :id_item"); $stmt->bindParam("kasir",$kasir); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getCheckProduk4($cashier,$uniqid,$id_item ){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from purchase_order where uniqid= :uniqid and id_user = :cashier and id_item = :id_item"); $stmt->bindParam("cashier",$cashier); $stmt->bindParam("uniqid",$uniqid); $stmt->bindParam("id_item",$id_item); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->rowCount(); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getTransSale($awal,$akhir,$order = 'desc') { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.`sale_date`,a.`sale_id`, (SELECT SUM((d.price - (d.price*(d.disc_prc/100)))*d.qty) AS total FROM t_sale_detail d WHERE d.sale_id = a.sale_id)AS total, c.`username`,a.sts,a.note,a.paid,a.disc_rp FROM t_sale a INNER JOIN m_user c ON a.`id_user` = c.`id_user` where (a.`sale_date` BETWEEN :awal AND :akhir) and a.sts < 2 ORDER BY sale_id ".$order ); $stmt->bindParam("awal",$awal); $stmt->bindParam("akhir",$akhir); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //detalle de una venta public function getDetails($sale){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from t_sale_detail where sale_id = :sale_id "); $stmt->bindParam("sale_id",$sale); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //SELECT sum(qty) as cantidad FROM `t_sale_detail` WHERE `sale_id` = "J230702002"; public function getSellCantidad($sale){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT sum(qty) as cantidad FROM `t_sale_detail` where sale_id = :sale_id "); $stmt->bindParam("sale_id",$sale); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getTransCot($awal,$akhir,$order = 'desc') { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.`sale_date`,a.`sale_id`, (SELECT SUM((d.price - (d.price*(d.disc_prc/100)))*d.qty) AS total FROM t_sale_detail d WHERE d.sale_id = a.sale_id)AS total, c.`username`,a.sts,a.note,a.paid,a.disc_rp FROM t_sale a INNER JOIN m_user c ON a.`id_user` = c.`id_user` where (a.`sale_date` BETWEEN :awal AND :akhir) and a.sts > 1 ORDER BY sale_id ".$order ); $stmt->bindParam("awal",$awal); $stmt->bindParam("akhir",$akhir); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getTransOC_P($awal,$akhir) { $db = $this->dblocal; try { $stmt = $db->prepare(" SELECT * FROM `re` a WHERE a.`created_at` > :awal AND a.`created_at` < :akhir AND a.`operation_type_id` > 1 "); $stmt->bindParam("awal",$awal); $stmt->bindParam("akhir",$akhir); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getTransSaleDev($awal,$akhir,$order = 'desc',$id = '0') { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.`sale_date`,a.`sale_id`, (SELECT SUM((d.price - (d.price*(d.disc_prc/100)))*d.qty) AS total FROM t_sale_detail d WHERE d.sale_id = a.sale_id)AS total, c.`username`,a.sts,a.paid,a.disc_rp FROM t_sale a INNER JOIN m_user c ON a.`id_user` = c.`id_user` where sts = :id AND (a.`sale_date` BETWEEN :awal AND :akhir) ORDER BY sale_id ".$order ); $stmt->bindParam("awal",$awal); $stmt->bindParam("akhir",$akhir); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getSaleId($id){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.* ,c.`username` FROM t_sale a INNER JOIN m_user c ON a.`id_user` = c.`id_user` where a.sale_id = :id"); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getSaleDetailIdSale($id) { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT @rownum := @rownum + 1 AS urutan, a.*, (a.price - ((a.price * a.disc_prc) /100) ) * a.qty as total from t_sale_detail a,(SELECT @rownum := 0) r where a.sale_id = :id"); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchall(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /****************************************************************************** END TABEL T_JUAL *******************************************************************************/ /****************************************************************************** START OF pos MENU CODE *******************************************************************************/ public function getMenu() { $db = $this->dblocal; try { $stmt = $db->prepare("select * from r_menu order by menu_order"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getSubMenu($id) { $db = $this->dblocal; try { $stmt = $db->prepare("select * from r_menu_sub where id_menu = :id order by sub_menu_order asc"); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getIdMenu($id) { $db = $this->dblocal; try { $stmt = $db->prepare("select * from r_menu_sub where id_sub_menu = :id order by sub_menu_order asc"); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //insertamos el registro error cfdi public function saveErrorCFDI( $sale_id,$code,$message) { $db = $this->dblocal; try { // $stmt = $db->prepare("insert into temp_sale(id_user, uniqid, id_item, barcode, item_name, qty, unit, price, discprc, discrp) values (:cashier , :uniqid , :id_item, :barcode, :item_name, :qty, :unit, :price, :discprn, :discrp)"); $stmt = $db->prepare("insert into error_cfdi( sale_id, code, message) values ( :sale_id, :code, :message ) "); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("code",$code); $stmt->bindParam("message",$message); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /*********************query for system*********************/ public function getLogin($user,$pass) { $db = $this->dblocal; try { $stmt = $db->prepare("select a.*, (select name_shop from r_ref_system where id = 1) as name_shop, (select address_shop from r_ref_system where id = 1) as address_shop, (select phone_shop from r_ref_system where id = 1) as phone_shop from m_user a where upper(a.username)=upper(:user) and a.pass_user=md5(:id)"); $stmt->bindParam("user",$user); $stmt->bindParam("id",$pass); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); $stat[2] = $stmt->rowCount(); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); $stat[2] = 0; return $stat; } $stmt->close(); } public function getrefsytem() { $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from configuration a where id = 28 "); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); $stat[2] = 0; return $stat; } } public function getrefsytem2() { $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from configuration a where id = 29 "); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); $stat[2] = 0; return $stat; } } public function getrefsytem3() { $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from configuration a where id = 30 "); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); $stat[2] = 0; return $stat; } } //buscar valor de configuration public function getByPreffix($short) { $db = $this->dblocal; try { $stmt = $db->prepare("select a.val from configuration a where short=\"$short\" "); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); $stat[2] = 0; return $stat; } } public function updateSettingSaldo($short) { $db = $this->dblocal; try { $stmt = $db->prepare("update configuration set val=val-1 where short= :short"); $stmt->bindParam("short",$short); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Edit!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getrefsytemX() { $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from r_ref_system a where id = 1 "); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); $stat[2] = 0; return $stat; } } public function getSubMenuById($menu) { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT name_sub_menu FROM r_menu_sub WHERE id_sub_menu= :menu"); $stmt->bindParam("menu",$menu); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchColumn(0); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //actualizar usuario unico en tabla m_user public function updateUniqLogin($id_user,$uniq_login) { $db = $this->dblocal; try { $stmt = $db->prepare("update m_user set uniq_login = :uniq_login where id_user = :id_user"); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("uniq_login",$uniq_login); $stmt->execute(); $stat[0] = true; $stat[1] = "cambio exitoso!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //insertar usuario que acceso al sistema public function saveUniqUser($id_user,$access) { $db = $this->dblocal; try { $stmt = $db->prepare("insert into sessions(id_user,access) values(:id_user,:access)"); $stmt->bindParam("id_user",$id_user); $stmt->bindParam("access",$access); $stmt->execute(); $stat[0] = true; $stat[1] = "Sukses save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //borramos sesiones public function deleteUniqUser($iduser) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from sessions where id_user = :id"); $stmt->bindParam("id",$iduser); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Delete sessions!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /*********************query for master user*********************/ public function getListUser() { $db = $this->dblocal; try { $stmt = $db->prepare("select * from m_user where username<>'admin' order by username desc"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getUserMenu($username) { $db = $this->dblocal; try { $stmt = $db->prepare("select * from m_user where username = :username order by username desc"); $stmt->bindParam("username",$username); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function saveUser($username,$pass_user,$h_menu,$stock_id) { $db = $this->dblocal; try { $stmt = $db->prepare("insert into m_user(username,pass_user,h_menu,stock_id) values(:name,MD5(:pass),:hmenu)"); $stmt->bindParam("name",$username); $stmt->bindParam("pass",$pass_user); $stmt->bindParam("hmenu",$h_menu); $stmt->bindParam("stock_id",$stock_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Sukses save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateUser($id_user,$username,$h_menu,$stock_id) { $db = $this->dblocal; try { $stmt = $db->prepare("update m_user set username = :name, h_menu = :hmenu , stock_id=:stock_id where id_user = :id"); $stmt->bindParam("name",$username); $stmt->bindParam("id",$id_user); $stmt->bindParam("hmenu",$h_menu); $stmt->bindParam("stock_id",$stock_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Sukses update!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function updateUserKind($id_user,$kind) { $db = $this->dblocal; try { $stmt = $db->prepare("UPDATE `m_user` SET `kind` = :kind WHERE `m_user`.`id_user` = :id "); $stmt->bindParam("id",$id_user); $stmt->bindParam("kind",$kind); $stmt->execute(); $stat[0] = true; $stat[1] = "Sukses update!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function deleteUser($id_user) { $db = $this->dblocal; try { $stmt = $db->prepare("delete from m_user where id_user = :id"); $stmt->bindParam("id",$id_user); $stmt->execute(); $stat[0] = true; $stat[1] = "Sukses update!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function checkPassword($id,$pass) { $db = $this->dblocal; try { $stmt = $db->prepare("select * from m_user where id_user = :id and pass_user = md5(:pass) and kind = 1"); $stmt->bindParam("id",$id); $stmt->bindParam("pass",$pass); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->rowCount(); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function resetPass($iduser,$pass) { $db = $this->dblocal; try { $stmt = $db->prepare("update m_user set pass_user = md5(:pass) where id_user=:id"); $stmt->bindParam("id",$iduser); $stmt->bindParam("pass",$pass); $stmt->execute(); $stat[0] = true; $stat[1] = "Sukses reset pass!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /****************************************************************************** END OF MENU CODE *******************************************************************************/ /****************************************************************************** INI OF OPERATION2 *******************************************************************************/ public function getbyid($barcode){ $db = $this->dblocal; try { $stmt = $db->prepare("select a.id from product a where a.barcode = :id "); $stmt->bindParam("id",$barcode); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function searchEntradas($awal,$akhir,$order = 'desc',$id = '0') { $db = $this->dblocal; try { $stmt = $db->prepare("SELECT a.`sale_date`,a.`sale_id`, (SELECT SUM((d.price - (d.price*(d.disc_prc/100)))*d.qty) AS total FROM t_sale_detail d WHERE d.sale_id = a.sale_id)AS total, c.`username`,a.sts,a.paid,a.disc_rp FROM t_sale a INNER JOIN m_user c ON a.`id_user` = c.`id_user` where sts = :id AND (a.`sale_date` BETWEEN :awal AND :akhir) ORDER BY sale_id ".$order ); $stmt->bindParam("awal",$awal); $stmt->bindParam("akhir",$akhir); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //datos de la venta tabla sell public function getlistSell($id){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from sell where sale_id = :id "); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //datos de la venta tabla sell public function getSell($id){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from sell where id = :id "); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //actualizamos status de facturas public function updateFacturaSell($sale_id,$uuid) { $db = $this->dblocal; try { //J221215013 244e0241-648c-46dd-a903-33ce42938922 $stmt = $db->prepare("UPDATE `facturaok` SET `name` = :uuid , is_service = 1 where sale_id = :sale_id "); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("uuid",$uuid); $stmt->execute(); $stat[0] = true; $stat[1] = "Success editar factura!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //actualizamos status de facturas c/nombre y rfc public function updateFacturaSellClient($sale_id,$uuid,$name,$rfc) { $db = $this->dblocal; try { //J221215013 244e0241-648c-46dd-a903-33ce42938922 $stmt = $db->prepare("UPDATE `facturaok` SET `name` = :uuid , is_service = 1, presentation = :name, description=:rfc where sale_id = :sale_id "); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("uuid",$uuid); $stmt->bindParam("name",$name); $stmt->bindParam("rfc",$rfc); $stmt->execute(); $stat[0] = true; $stat[1] = "Success editar factura!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //actualizamos status de facturas HONORARIOS public function updateFacturaSellH($sale_id,$uuid) { $db = $this->dblocal; try { //J221215013 244e0241-648c-46dd-a903-33ce42938922 $stmt = $db->prepare("UPDATE `facturaok` SET `name` = :uuid , is_service = 2 where sale_id = :sale_id "); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("uuid",$uuid); $stmt->execute(); $stat[0] = true; $stat[1] = "Success editar factura!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //actualizamos status de ENVIO DE facturas public function updateFacturaEmail($sale_id) { $db = $this->dblocal; try { //J221215013 244e0241-648c-46dd-a903-33ce42938922 $stmt = $db->prepare("UPDATE `facturaok` SET email_sts = email_sts+1 where sale_id = :sale_id "); $stmt->bindParam("sale_id",$sale_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success envio de factura!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //detalle de la venta public function getOperations($id){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from t_sale_detail where sale_id = :id "); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchall(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //obtenemos la forma de pago public function getFormakId($id){ $db = $this->dblocal; try { $stmt = $db->prepare("select * from formapago where id = :id "); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //insertamos el registro de la factura generada en facturaOK public function saveFacturaSell($mail,$uuid,$rfc,$sell_id,$sale_id,$subtotal,$impuestos,$total,$iva,$name,$user_id) { $db = $this->dblocal; try { // $stmt = $db->prepare("insert into temp_sale(id_user, uniqid, id_item, barcode, item_name, qty, unit, price, discprc, discrp) values (:cashier , :uniqid , :id_item, :barcode, :item_name, :qty, :unit, :price, :discprn, :discrp)"); $stmt = $db->prepare("insert into facturaok( image, name, description, sell_id, sale_id, subtotal, impuestos, price_out, unit, presentation, user_id, created_at,is_service) values ( :mail, :uuid, :rfc, :sell_id, :sale_id, :subtotal, :impuestos, :total, :iva, :name, :user_id,now(),1 ) "); $stmt->bindParam("mail",$mail); $stmt->bindParam("uuid",$uuid); $stmt->bindParam("rfc",$rfc); $stmt->bindParam("sell_id",$sell_id); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("subtotal",$subtotal); $stmt->bindParam("impuestos",$impuestos); $stmt->bindParam("total",$total); $stmt->bindParam("iva",$iva); $stmt->bindParam("name",$name); $stmt->bindParam("user_id",$user_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //insertamos el registro de la factura HONORARIOS en facturaOK public function saveFacturaHono($mail,$uuid,$rfc,$sell_id,$sale_id , $subtotal, $impuesto ,$total,$iva,$name,$user_id) { $db = $this->dblocal; try { // $stmt = $db->prepare("insert into temp_sale(id_user, uniqid, id_item, barcode, item_name, qty, unit, price, discprc, discrp) values (:cashier , :uniqid , :id_item, :barcode, :item_name, :qty, :unit, :price, :discprn, :discrp)"); $stmt = $db->prepare("insert into facturaok( image, name, description, sell_id, sale_id, subtotal, impuestos, price_out, unit, presentation, user_id, created_at,is_service) values ( :mail, :uuid, :rfc, :sell_id, :sale_id, :subtotal, :impuestos ,:total, :iva, :name, :user_id,now(),4 ) "); $stmt->bindParam("mail",$mail); $stmt->bindParam("uuid",$uuid); $stmt->bindParam("rfc",$rfc); $stmt->bindParam("sell_id",$sell_id); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("subtotal",$subtotal); $stmt->bindParam("impuestos",$impuestos); $stmt->bindParam("total",$total); $stmt->bindParam("iva",$iva); $stmt->bindParam("name",$name); $stmt->bindParam("user_id",$user_id); $stmt->execute(); $stat[0] = true; $stat[1] = "Success Save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function list_inventary() { $db = $this->dblocal; try { $stmt = $db->prepare("select * from m_item order by stock DESC"); $stmt->execute(); $stat[0] = true; $stat[1] = "List inventary"; $stat[2] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); $stat[2] = []; return $stat; } } //id maximo de facturas public function getByFacturaMax(){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT MAX(id) AS id from `facturaok` "); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //id de facturas public function getByFacturaSellExist($sell_id){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT id AS id from `facturaok` where `is_active`=1 and `is_service`=1"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //id de facturas public function getByFacturaSellExistOK($id){ $db = $this->dblocal; try { $stmt = $db->prepare("SELECT *from `facturaok` where sell_id = :id"); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } /****************************************************************************** END OF OPERATION2 CODE *******************************************************************************/ //guardar datos de hardware ESP public function savetemperature($chipid,$temperatura,$humedad,$sensor){ $db = $this->dblocal; try { $stmt = $db->prepare("insert into data(data_device_sn,data_temp,data_hum,data_sensor) values(:chipid,:temperatura,:humedad,:sensor)"); $stmt->bindParam("chipid",$chipid); $stmt->bindParam("temperatura",$temperatura); $stmt->bindParam("humedad",$humedad); $stmt->bindParam("sensor",$sensor); $stmt->execute(); $stat[0] = true; $stat[1] = "Success save!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } //actualizamos status de facturas public function updateFacturaSellM($sale_id,$uuid) { $db = $this->dblocal; try { //J221215013 244e0241-648c-46dd-a903-33ce42938922 $stmt = $db->prepare("UPDATE `facturaok_M` SET `name` = :uuid , is_service = 1 where sale_id = :sale_id "); $stmt->bindParam("sale_id",$sale_id); $stmt->bindParam("uuid",$uuid); $stmt->execute(); $stat[0] = true; $stat[1] = "Success editar factura!"; return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } } ?>