gongpex Posted September 1, 2015 Share Posted September 1, 2015 Hello veryone, Today I tried to make validation to prevent automatic order if stock product on databse not enough to process, this is my code : $query = $this->db->query("select * from headerautoorder"); $time = Date('Ymd'); $today = Date('d'); $day= Date('D'); if($query->num_rows > 0) { // core if $no = 0; foreach($query->result() as $rows) { // core foreach $idautoorder = $rows->idautoorder; $tgl_order = $rows->tgltransaksi; $tglakhir = $rows->tglakhir; $tipe = $rows->tipe; $keterangan = $rows->keterangan; $total_payment = $rows->total; $idmember = $rows->idmember; //this is my question : is this code true? this to check if stock is enough or not for transaction $cekdetail = $this->db->query("select * from detailautoorder where idautoorder='$idautoorder'"); $permintaan=array(); foreach($cekdetail->result() as $hdetail) { $idbarang = $hdetail->idbarang; $jbrg = $hdetail->jmlitem; $permintaan[$idbarang] = $jbrg; } foreach($permintaan as $idbarang => $jbrg) { $q='select * from barang where status > 0 and idbarang='.$this->db->escape($idbarang); $brgdata = $this->db->query($q)->row_array(); $stock = $brgdata['stock']; if($stock < $jbrg) { $flag = FALSE; } } # end foreach # primary if # if($flag == TRUE) { echo 'succesfull'; } else { echo 'failed'; } # end primary if } # end if core } # end core foreach I have 4 table on database : - headerautoorder - detailautoorder - order - detailorder My code located on login area , so after user succesfull login this code will be executed automatically, This code purpose to filter whether the stock of product is enough or not please help me this code is true or still has a mistake note : if you confuse I will give you screenshot of my database thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted September 1, 2015 Share Posted September 1, 2015 Does that work? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now