Advertisement
fadlyshafa

Untitled

Apr 5th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.84 KB | None | 0 0
  1. <?php
  2.  
  3. defined('BASEPATH') OR exit('No direct script access allowed');
  4.  
  5. class Customer_model extends CI_Model {
  6.  
  7. function __construct() {
  8. parent::__construct();
  9. }
  10.  
  11. /*
  12. return country
  13. */
  14.  
  15. public function getCountry() {
  16. return $this->db->get('countries')->result();
  17. }
  18.  
  19. /*
  20. return state
  21. */
  22.  
  23. public function getQuotationCustomer($id) {
  24. $this->db->select('q.*,b.*,c.*')
  25. ->from('quotation q')
  26. ->join('biller b', 'q.biller_id=b.biller_id', 'left')
  27. ->join('customer c', 'q.customer_id=c.customer_id', 'left')
  28. ->where('q.customer_id', $id);
  29. return $this->db->get()->result();
  30. }
  31.  
  32. public function getworkorderCustomer($id) {
  33. $this->db->select('d.*,u.*')
  34. ->from('workorder d')
  35. ->join('customer u', 'u.customer_id = d.workorder_costumer', 'left')
  36. ->where('d.workorder_costumer', $id);
  37. return $this->db->get()->result();
  38. }
  39.  
  40. public function getState($id) {
  41. return $this->db->select('s.*')
  42. ->from('states s')
  43. ->join('countries c', 'c.id = s.country_id', 'left')
  44. ->where('s.country_id', $id)
  45. ->get()
  46. ->result();
  47. }
  48.  
  49. /*
  50. return city
  51. */
  52.  
  53. public function getCity($id) {
  54. return $this->db->select('c.*')
  55. ->from('cities c')
  56. ->join('states s', 's.id = c.state_id', 'left')
  57. ->where('c.state_id', $id)
  58. ->get()
  59. ->result();
  60. }
  61.  
  62. public function generateNumber($id) {
  63. return $this->db->select('c.*')
  64. ->from('cities c')
  65. ->join('states s', 's.id = c.state_id', 'left')
  66. ->where('c.state_id', $id)
  67. ->get()
  68. ->result();
  69. }
  70.  
  71. public function getCities() {
  72. $sql = "select * from cities where state_id >= 4121";
  73.  
  74. return $this->db->query($sql)
  75. ->result();
  76. }
  77.  
  78. public function getStates() {
  79.  
  80. return $this->db->select('*')
  81. ->from('states')
  82. ->where('country_id', 102)
  83. ->get()
  84. ->result();
  85. }
  86.  
  87. /*
  88. return all customer details to dispaly list
  89. */
  90.  
  91. public function getCustomer() {
  92. $data = $this->db->select('b.*,c.name as cname,ct.name as ctname')
  93. ->from('customer b')
  94. ->join('countries c', 'c.id = b.country_id', 'left')
  95. ->join('cities ct', 'ct.id = b.city_id', 'left')
  96. ->get()
  97. ->result();
  98. return $data;
  99. }
  100.  
  101. public function getCustomerSales() {
  102. $data = $this->db->select('b.customer_name,b.customer_id')
  103. ->from('customer b')
  104. ->group_by('b.customer_id')
  105. ->get()
  106. ->result();
  107. return $data;
  108. }
  109.  
  110. public function get_sales_customer(){
  111. $data = $this->db->select('c.customer_id,c.customer_name,sum(s.total) as total')
  112. ->from('customer c')
  113. ->join('sales s','s.customer_id = c.customer_id','left')
  114. ->group_by('c.customer_id')
  115. ->get()
  116. ->result();
  117. return $data;
  118. }
  119.  
  120. public function get_sales_customer_filter($awal,$akhir){
  121. $data = $this->db->select('c.customer_id,c.customer_name,sum(s.total) as total')
  122. ->from('customer c')
  123. ->join('sales s','s.customer_id = c.customer_id','left')
  124. ->where('s.date >=',$awal)
  125. ->where('s.date <=',$akhir)
  126. ->group_by('c.customer_id')
  127. ->get()
  128. ->result();
  129. return $data;
  130. }
  131.  
  132. public function getCustomerAddress() {
  133. $data = $this->db->select('b.*,c.name as cname,ct.name as ctname, m.name as cmname')
  134. ->from('customer_address b')
  135. ->join('customer m', 'm.id = b.customer_id', 'left')
  136. ->join('countries c', 'c.id = b.country', 'left')
  137. ->join('cities ct', 'ct.id = b.city', 'left')
  138. ->get()
  139. ->result();
  140. return $data;
  141. }
  142.  
  143. public function getCustomerAddressID($id) {
  144. $data = $this->db->select('b.*,c.name as cname,ct.name as ctname,m.customer_name as mname')
  145. ->from('customer_address b')
  146. ->join('customer m', 'm.customer_id = b.customer_id', 'left')
  147. ->join('countries c', 'c.id = b.country', 'left')
  148. ->join('cities ct', 'ct.id = b.city', 'left')
  149. ->where('b.customer_id', $id)
  150. ->get()
  151. ->result();
  152. return $data;
  153. }
  154.  
  155. public function getCustomerAddressbyID($id) {
  156. $data = $this->db->select('b.*,c.name as cname,ct.name as ctname,m.customer_name as mname,s.name as sname,b.address as baddress')
  157. ->from('customer_address b')
  158. ->join('customer m', 'm.customer_id = b.customer_id', 'left')
  159. ->join('countries c', 'c.id = b.country', 'left')
  160. ->join('cities ct', 'ct.id = b.city', 'left')
  161. ->join('states s', 's.id = b.state', 'left')
  162. ->where('b.id', $id)
  163. ->get()
  164. ->result();
  165. return $data;
  166. }
  167.  
  168. public function getCustomerUserID($id) {
  169. $data = $this->db->select('*')
  170. ->from('customer_user b')
  171. ->where('b.customer_id', $id)
  172. ->get()
  173. ->result();
  174. return $data;
  175. }
  176.  
  177. public function checkField($field, $where) {
  178. $data = $this->db->select('count(*)')
  179. ->from('customer')
  180. ->like($field, $where)
  181. ->get()
  182. ->num_rows();
  183. return $data;
  184. }
  185.  
  186. public function getField($field) {
  187. $data = $this->db->distinct()
  188. ->select($field)
  189. ->from('customer')
  190. ->get()
  191. ->result();
  192. return $data;
  193. }
  194.  
  195. public function getCustorder($id) {
  196. $data = $this->db->select('c.*,so.*,b.*,i.*')
  197. ->from('customer c')
  198. ->join('sales so', 'so.customer_id = c.customer_id', 'left')
  199. ->join('biller b', 'so.biller_id=b.biller_id', 'left')
  200. ->join('invoice i ', 'so.sales_id=i.sales_id', 'left')
  201. ->where('so.customer_id', $id)
  202. ->get()
  203. ->result();
  204. return $data;
  205. }
  206.  
  207. /*
  208. insert new customer record in databse
  209. */
  210. public function addModel2($data)
  211. {
  212. if($this->db->insert('customer',$data))
  213. {
  214. return $this->db->insert_id();
  215. }
  216. else{
  217. return FALSE;
  218. }
  219. }
  220.  
  221. public function addModel($data) {
  222. $sql = "insert into customer (gst_registration_type, customer_name, company_name, gstid, country_id, state_id, state_code, city_id, postal_code, no_telp, mobile, fax, email, jalan, blok, nomor, rt, rw, kelurahan, kecamatan, cf1, cf2) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  223. if ($this->db->query($sql, $data)) {
  224. return $this->db->insert_id();
  225. } else {
  226. return FALSE;
  227. }
  228. }
  229.  
  230. public function addAddressModel($data) {
  231. $sql = "insert into customer_address (customer_id,type,country,state,city,address,zip,tel) values(?,?,?,?,?,?,?,?)";
  232. if ($this->db->query($sql, $data)) {
  233. return $this->db->insert_id();
  234. } else {
  235. //print_r($this->db->error());
  236. return FALSE;
  237. }
  238. }
  239.  
  240. public function addUserModel($data) {
  241. $sql = "insert into customer_user (customer_id,name,title,tel,ph,email,info) values(?,?,?,?,?,?,?)";
  242. if ($this->db->query($sql, $data)) {
  243. return $this->db->insert_id();
  244. } else {
  245. //print_r($this->db->error());
  246. return FALSE;
  247. }
  248. }
  249.  
  250. /*
  251. return specific customer record
  252. */
  253.  
  254. public function getRecord($id) {
  255. $query = $this->db->select('customer.*, cities.name AS ciname, countries.name AS coname')
  256. ->from("customer")
  257. ->join('cities', 'cities.id = customer.city_id', 'left')
  258. ->join('countries', 'countries.id = customer.country_id', 'left')
  259. ->where('customer.customer_id', $id)
  260. ->get()
  261. ->result();
  262. if ($query) {
  263. return $query;
  264. } else {
  265. return FALSE;
  266. }
  267. }
  268.  
  269. public function getAddressRecord($id) {
  270. $sql = "select * from customer_address where customer_id = ? and id = ?";
  271. if ($query = $this->db->query($sql, $id)) {
  272. return $query->result();
  273. } else {
  274. return FALSE;
  275. }
  276. }
  277.  
  278. public function getListAddressRecord($id) {
  279. $sql = "select * from customer_address where customer_id = ?";
  280. if ($query = $this->db->query($sql, array($id))) {
  281. return $query->result();
  282. } else {
  283. return FALSE;
  284. }
  285. }
  286.  
  287. public function getUserRecord($id) {
  288. $sql = "select * from customer_user where customer_id = ? and id = ?";
  289. if ($query = $this->db->query($sql, $id)) {
  290. return $query->result();
  291. } else {
  292. return FALSE;
  293. }
  294. }
  295.  
  296. /*
  297. save edited customer record in databse
  298. */
  299.  
  300. public function editModel($data, $id) {
  301. /* $sql = "update customer set customer_name = ?,company_name = ?,address = ?,city_id = ?,country_id = ?,state_id = ?,mobile = ?,email = ?,postal_code = ?,gstid=?,vat_no=?,pan_no=?,tan_no=?,cst_reg_no=?,excise_reg_no=?,lbt_reg_no,servicetax_reg_no=?,gst_registration_type=? where customer_id = ?"; */
  302. //if($this->db->query($sql,$data)){
  303. $this->db->where('customer_id', $id);
  304. if ($this->db->update('customer', $data)) {
  305. return TRUE;
  306. } else {
  307. return FALSE;
  308. }
  309. }
  310.  
  311. public function editAddressModel($data, $id, $ida) {
  312. $this->db->where('customer_id', $id);
  313. $this->db->where('id', $ida);
  314. if ($this->db->update('customer_address', $data)) {
  315. return TRUE;
  316. } else {
  317. return FALSE;
  318. }
  319. }
  320.  
  321. public function editUserModel($data, $id, $ida) {
  322. $this->db->where('customer_id', $id);
  323. $this->db->where('id', $ida);
  324. if ($this->db->update('customer_user', $data)) {
  325. return TRUE;
  326. } else {
  327. return FALSE;
  328. }
  329. }
  330.  
  331. /*
  332. delete customer record in databse
  333. */
  334.  
  335. public function deleteModel($id) {
  336. $sql = "delete from customer where customer_id = ?";
  337. if ($this->db->query($sql, array($id))) {
  338. /* $this->db->where('customer_id',$id);
  339. if($this->db->delete('customer')){ */
  340. return TRUE;
  341. } else {
  342. return FALSE;
  343. }
  344. }
  345.  
  346. public function deleteAddressModel($id) {
  347. $sql = "delete from customer_address where id = ?";
  348. if ($this->db->query($sql, array($id))) {
  349. return TRUE;
  350. } else {
  351. return FALSE;
  352. }
  353. }
  354.  
  355. public function deleteUserModel($id) {
  356. $sql = "delete from customer_user where id = ?";
  357. if ($this->db->query($sql, array($id))) {
  358. return TRUE;
  359. } else {
  360. return FALSE;
  361. }
  362. }
  363.  
  364. }
  365.  
  366. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement