public static function moveStock($prod_id, $jumlah, $minus = 1, $note = "", $po_id = 0)
 {
     $prod = new ProdModel();
     $prod->getByID($prod_id);
     //isi log
     $ps = new ProdStok();
     $ps->stok_date = leap_mysqldate();
     $ps->stok_prev = $prod->prod_stock;
     $ps->stok_po_id = $po_id;
     $ps->stok_prod_id = $prod->prod_id;
     $ps->stok_userid = Account::getMyID();
     if ($minus) {
         //kurangi stok
         $prod->prod_stock -= $jumlah;
     } else {
         //kurangi stok
         $prod->prod_stock += $jumlah;
     }
     $prod->load = 1;
     $prod->save();
     if (Role::hasRole('admin')) {
         $ps->stock_admin = 1;
     }
     $ps->stock_note = $note;
     $ps->stok_actual = $prod->prod_stock;
     if ($ps->stok_prev > $ps->stok_actual) {
         $ps->stok_debit_credit = 1;
     } else {
         $ps->stok_debit_credit = 0;
     }
     return $ps->save();
 }
    public function inputProduct()
    {
        $cam = new CampaignModel();
        $arrCam = $cam->getAll();
        $prod = new ProdModel();
        $arrProd = $prod->getAll();
        $_SESSION['arrProd'] = $arrProd;
        ?>
<div class="input-group">
      
      <span class="input-group-addon" id="basic-addon1">Select Campaign :</span>
      <select class="form-control" onchange="getMatrix();" id="camp_select">
        <option value=""></option>
        <?php 
        foreach ($arrCam as $c) {
            ?>
        <option value="<?php 
            echo $c->camp_id;
            ?>
"><?php 
            echo $c->camp_name;
            ?>
</option>
        <?php 
        }
        ?>
    </select>
</div><!-- /input-group -->
    
 

<div id="camp_matrix" style="padding-top: 20px;">
    
</div>

<script>
function getMatrix(){
    var slc = $("#camp_select").val();
    if(slc!="")
    $("#camp_matrix").load("<?php 
        echo _SPPATH;
        ?>
CampaignWeb/getMatrix?cid="+slc);
}
</script>
<style>
    .productcamp{
        background-color: #dedede;
        margin: 5px;
        padding: 5px;
    }
    
</style>
        <?php 
        //pr($arrProd);
    }
Example #3
0
    public function category($args)
    {
        list($name, $page) = $args;
        // $name;
        $name = urldecode($name);
        $cat = new ProdCat();
        $arr = $cat->getWhere("cat_name LIKE '{$name}'");
        // echo $name;
        ?>
		<style>
			.judulcategory {
				padding-top  : 20px;

				padding-left : 15px;
				color        : #AAA;
				font-size    : 14px;

			}

			.judulcategory a {
				font-size   : 14px;
				color       : #AAA;
				font-family : 'Open Sans', sans-serif;
				font-weight : normal;
			}

			.judulcategory a:hover {
				text-decoration : underline;
			}

			.h1category {
				padding-top    : 20px;
				padding-bottom : 0px;
				padding-left   : 15px;
				margin         : 0;
				padding-bottom : 30px;
				color          : #000;
				font-style     : italic;
				font-family    : 'Libre Baskerville', serif;
				font-size      : 28px;

			}
		</style>

		<?php 
        if (count($arr) > 0) {
            // pr($arr);
            $arrParent = array();
            $arrpp = ProdCat::getAllParents($arr[0]->cat_parent_id, $arrParent);
            //pr($arrpp);
            $arrpp2 = array_reverse($arrpp);
            foreach ($arrpp2 as $bc) {
                $str[] = "<a href='" . _SPPATH . "pwa/category/" . urlencode($bc->cat_name) . "'>" . $bc->cat_name . "</a>";
            }
            /*
             * print breadcrumbs
            if(count($arrpp2)>0)
            echo "<div class='judulcategory'>".implode(" > ",$str)." > </div>";
            */
            ?>
			<h1 class="h1category"><?php 
            echo ucwords($name);
            ?>
</h1>
			<?php 
            $pc = new ProdModel();
            //pagination
            if ($page < 1 || $page == "") {
                $page = 1;
            }
            $limit = 21;
            $begin = ($page - 1) * $limit;
            $link = _SPPATH . "pwa/category/" . urlencode($name) . "/|x|";
            $jml = $pc->getJumlah("prod_cat_id = '{$arr[0]->cat_id}'");
            //end pagination
            $arrp = $pc->getWhere("prod_cat_id = '{$arr[0]->cat_id}' LIMIT {$begin},{$limit}");
            //pr($arrp);
            foreach ($arrp as $num => $prod) {
                $cw = new Cw();
                $cw->productPrinter($prod);
                if ($num % 3 == 2) {
                    ?>
					<div class="clearfix"></div>
				<?php 
                }
            }
            ?>
			<div class="clearfix"></div>
			<div class="gantihal"
			     style="text-align: center;">

				<?php 
            //begin pagination
            BootstrapUX::pagination($page, $jml, $limit, $link);
            ?>
			</div>
		<?php 
        }
    }
    function show()
    {
        $arr = self::getCart();
        $arr_bulk = self::getCartBulk();
        //pr($arr_bulk);
        //pr($arr);
        //$qty = isset($_GET['qty'])?addslashes($_GET['qty']):1;
        $out_of_stock = 0;
        $arrOOS = self::cekStok();
        //pr($arrOOS);
        $out_of_stock = count($arrOOS);
        ?>
<style>
    h1.order{
        padding: 0;
margin: 0;
color: #111;
font-style: italic;
font-family: 'Libre Baskerville', serif;
font-size: 32px;
margin-bottom: 20px;
    }
    #fullholder{
        background-color: #efefef;
    }
    .foto100 img{
        width: 100px;
        
    }
    .headertab th{
        text-align: center;
    }
    tr.headertab{
        background-color: #efefef;
    }
    td.rp{
        text-align: right;
        
    }
    .image_oos{
        border:1px solid red;
    }
    

</style>
<style>
#squaresWaveG{
position:relative;
width:50px;
height:6px}

.squaresWaveG{
position:absolute;
top:0;
background-color:#C2C2C2;
width:6px;
height:6px;
-moz-animation-name:bounce_squaresWaveG;
-moz-animation-duration:1.3s;
-moz-animation-iteration-count:infinite;
-moz-animation-direction:linear;
-webkit-animation-name:bounce_squaresWaveG;
-webkit-animation-duration:1.3s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:linear;
-ms-animation-name:bounce_squaresWaveG;
-ms-animation-duration:1.3s;
-ms-animation-iteration-count:infinite;
-ms-animation-direction:linear;
-o-animation-name:bounce_squaresWaveG;
-o-animation-duration:1.3s;
-o-animation-iteration-count:infinite;
-o-animation-direction:linear;
animation-name:bounce_squaresWaveG;
animation-duration:1.3s;
animation-iteration-count:infinite;
animation-direction:linear;
}

#squaresWaveG_1{
left:0;
-moz-animation-delay:0.52s;
-webkit-animation-delay:0.52s;
-ms-animation-delay:0.52s;
-o-animation-delay:0.52s;
animation-delay:0.52s;
}

#squaresWaveG_2{
left:7px;
-moz-animation-delay:0.65s;
-webkit-animation-delay:0.65s;
-ms-animation-delay:0.65s;
-o-animation-delay:0.65s;
animation-delay:0.65s;
}

#squaresWaveG_3{
left:14px;
-moz-animation-delay:0.78s;
-webkit-animation-delay:0.78s;
-ms-animation-delay:0.78s;
-o-animation-delay:0.78s;
animation-delay:0.78s;
}

#squaresWaveG_4{
left:21px;
-moz-animation-delay:0.91s;
-webkit-animation-delay:0.91s;
-ms-animation-delay:0.91s;
-o-animation-delay:0.91s;
animation-delay:0.91s;
}

#squaresWaveG_5{
left:28px;
-moz-animation-delay:1.04s;
-webkit-animation-delay:1.04s;
-ms-animation-delay:1.04s;
-o-animation-delay:1.04s;
animation-delay:1.04s;
}

#squaresWaveG_6{
left:35px;
-moz-animation-delay:1.17s;
-webkit-animation-delay:1.17s;
-ms-animation-delay:1.17s;
-o-animation-delay:1.17s;
animation-delay:1.17s;
}

#squaresWaveG_7{
left:42px;
-moz-animation-delay:1.3s;
-webkit-animation-delay:1.3s;
-ms-animation-delay:1.3s;
-o-animation-delay:1.3s;
animation-delay:1.3s;
}

#squaresWaveG_8{
left:49px;
-moz-animation-delay:1.43s;
-webkit-animation-delay:1.43s;
-ms-animation-delay:1.43s;
-o-animation-delay:1.43s;
animation-delay:1.43s;
}

@-moz-keyframes bounce_squaresWaveG{
0%{
background-color:#C2C2C2;
}

100%{
background-color:#FFFFFF;
}

}

@-webkit-keyframes bounce_squaresWaveG{
0%{
background-color:#C2C2C2;
}

100%{
background-color:#FFFFFF;
}

}

@-ms-keyframes bounce_squaresWaveG{
0%{
background-color:#C2C2C2;
}

100%{
background-color:#FFFFFF;
}

}

@-o-keyframes bounce_squaresWaveG{
0%{
background-color:#C2C2C2;
}

100%{
background-color:#FFFFFF;
}

}

@keyframes bounce_squaresWaveG{
0%{
background-color:#C2C2C2;
}

100%{
background-color:#FFFFFF;
}

}

</style>


<div id="squaresWaveG" style="display:none; float: right; margin-right: 20px;">
<div id="squaresWaveG_1" class="squaresWaveG">
</div>
<div id="squaresWaveG_2" class="squaresWaveG">
</div>
<div id="squaresWaveG_3" class="squaresWaveG">
</div>
<div id="squaresWaveG_4" class="squaresWaveG">
</div>
<div id="squaresWaveG_5" class="squaresWaveG">
</div>
<div id="squaresWaveG_6" class="squaresWaveG">
</div>
<div id="squaresWaveG_7" class="squaresWaveG">
</div>
<div id="squaresWaveG_8" class="squaresWaveG">
</div>
</div>
<h1 class="order">Order Form </h1>

<div id="out_of_stock_alert" class="alert alert-danger" style="<?php 
        if (!$out_of_stock) {
            ?>
display:none;<?php 
        }
        ?>
">
        Jumlah Stok Tidak Mencukupi, Kurangi Jumlah Pesanan atau hapus pesanan anda.
 </div>

<div class="table-responsive">
    <table class="table table-bordered" style="background-color: #fff;">
    <thead>
        <tr class="headertab">
            <th><?php 
        echo Lang::t('No');
        ?>
</th>
            <th><?php 
        echo Lang::t('Image');
        ?>
</th>
            <th><?php 
        echo Lang::t('Name');
        ?>
</th>
            <th><?php 
        echo Lang::t('Price');
        ?>
</th>
            <th><?php 
        echo Lang::t('Qty');
        ?>
</th>
            <th><?php 
        echo Lang::t('Total');
        ?>
</th>
        </tr>
    </thead>
    <input type="hidden" value="<?php 
        echo $this->beratkardus;
        ?>
" id="beratkardus">
        <?php 
        $no = 0;
        $totalanb = 0;
        //isi berat awal
        $totalberat = $this->beratkardus;
        foreach ($arr_bulk as $numb => $objb) {
            $pid = $objb['id'];
            if ($pid == "" || $pid < 1) {
                continue;
            }
            $exp = explode(",", $pid);
            $no++;
            //berat paket
            $beratpaket = 0;
            //get all product
            $arrProd = array();
            $out_of_stock_bulk = 0;
            foreach ($exp as $numc => $obj_real) {
                $p = new ProdModel();
                $p->getByID($obj_real);
                $src = Pwa::getMainPic($p);
                $p->src = $src;
                $arrProd[] = $p;
                $beratpaket += $p->prod_berat_gram;
                if (in_array($obj_real, $arrOOS)) {
                    $out_of_stock_bulk = 1;
                }
            }
            ?>
    <input type="hidden" value="<?php 
            echo $beratpaket;
            ?>
" id="beratpaket_<?php 
            echo $numb;
            ?>
">
    <tr>
        <td><?php 
            echo $no;
            ?>
</td>
        <td>
            <?php 
            foreach ($arrProd as $numd => $prod) {
                ?>
            <div class="imageprod prod_<?php 
                echo $prod->prod_id;
                ?>
" style="width: 80px; height: 80px; overflow: hidden; float:left;">
                <img  src="<?php 
                echo $prod->src['thumbs'];
                ?>
" style="height:80px;">
            </div>
            <?php 
            }
            ?>
                
        </td>
        <td>
            <?php 
            foreach ($arrProd as $numd => $prod) {
                ?>
            <div class="prod_cart_name">
                <a target="_blank" href="<?php 
                echo _SPPATH;
                ?>
pwa/p/<?php 
                echo $prod->prod_id;
                ?>
/<?php 
                echo urlencode($prod->prod_name);
                ?>
">
                <?php 
                echo $prod->prod_name;
                ?>
                </a>
            </div>
            <?php 
            }
            ?>
            <i title='Remove Item from Cart' onclick="document.location='<?php 
            echo _SPPATH;
            ?>
cartweb/remItemBulk?id=<?php 
            echo $numb;
            ?>
';" style="cursor: pointer;" class="glyphicon glyphicon-remove"></i>
     
        </td>
        <td class="rp">
            <?php 
            $total_satu_bulk = 0;
            foreach ($arrProd as $numd => $prod) {
                $total_satu_bulk += $prod->prod_bulk_price;
            }
            echo "Rp." . rupiah($total_satu_bulk);
            ?>
                
        </td>
        <td style="text-align: center;">
            
            
            
        <input type="hidden" value="<?php 
            echo $total_satu_bulk;
            ?>
" id="hargabarubulk_<?php 
            echo $numb;
            ?>
">
        <select id="selectbulk_<?php 
            echo $numb;
            ?>
" >
        <?php 
            for ($x = 1; $x <= $this->max_order_qty_bulk; $x++) {
                ?>
        <option <?php 
                if ($objb['qty'] == $x) {
                    echo 'selected';
                }
                ?>
 value="<?php 
                echo $x;
                ?>
"><?php 
                echo $x;
                ?>
</option>
        <?php 
            }
            ?>
        </select>
        <script>
        $('#selectbulk_<?php 
            echo $numb;
            ?>
').change(function(){
            var slc = $('#selectbulk_<?php 
            echo $numb;
            ?>
').val();
            $('#squaresWaveG').show();
            $.get('<?php 
            echo _SPPATH;
            ?>
CartWeb/addQtyBulk?id=<?php 
            echo $numb;
            ?>
&qty='+slc,function(data){
                //alert(data);
                var slc = $('#selectbulk_<?php 
            echo $numb;
            ?>
').val();
                if(data.bool){
                    $('#out_of_stock').val('0');
                    $('#out_of_stock_alert').hide();
                    $('.imageprod').removeClass('image_oos');
                }else{
                    alert(data.err);
                    $('#out_of_stock_alert').show();
                    $('#out_of_stock').val('1');
                    var arr = data.oos;
                    $('.imageprod').removeClass('image_oos');
                    for(var key=0;key<arr.length;key++){
                        $('.prod_'+arr[key]).addClass('image_oos');
                    }
                }
                $('#squaresWaveG').hide();
                
            },'json');
                var hargabaru = $('#hargabarubulk_<?php 
            echo $numb;
            ?>
').val();
                var total = $('#totalAllHide').val();
                var subtotalLama = parseInt($('#subtotalhide_bulk_<?php 
            echo $numb;
            ?>
').val());


                var a = parseInt(slc);
                var harga = parseInt(hargabaru);
                var totalAll = parseInt(total);

                var subtotal = a*harga;
                var diff = subtotal-subtotalLama;
                //console.log(subtotal);
                $('#subtotal_bulk_<?php 
            echo $numb;
            ?>
').html('Rp.'+NilaiRupiah(subtotal)+',-');
                $('#subtotalhide_bulk_<?php 
            echo $numb;
            ?>
').val(subtotal);

                $('#totalAll').html('Rp.'+NilaiRupiah(totalAll+diff)+',-');

                $('#totalAllHide').val(totalAll+diff);
            
                //update berat
                
                var beratpaket = parseInt($('#beratpaket_<?php 
            echo $numb;
            ?>
').val());
                var beratretail = parseInt($('#beratretail').val());
                var beratkardus= parseInt($('#beratkardus').val());
                //isi ke tempatnya
                var kg = (beratkardus+beratretail+(beratpaket*slc))/1000;
                
                $('#jneweight').html(kg);
                $('#beratbulk').val(beratpaket*slc);
                $('#jneweight_hidden').val((beratkardus+beratretail+(beratpaket*slc)));
                
                var jne_kg_price = $('#jneprice_hidden').val();
                
                //hitung berdasarkan grenze
                var kg_batas = Math.floor(kg)+parseFloat(<?php 
            echo $this->jne_grenze;
            ?>
);
                if(kg>=kg_batas){
                    kg = Math.ceil(kg);
                }else{
                    kg = Math.floor(kg);
                }
                
                
                $('#totalShipCost').html('<b>Rp.'+NilaiRupiah(jne_kg_price*kg)+',-</b>');
                $('#totalAllPlusShipCost').html('<b>Rp.'+NilaiRupiah(totalAll+diff+(jne_kg_price*kg))+',-</b>');
                
                //for calculate
                $('#totalShipCost_hidden').val(jne_kg_price*kg);
                $('#totalAllPlusShipCost_hidden').val(totalAll+diff+(jne_kg_price*kg));
        });    
        
        
        </script>
            
        </td>
        <input type="hidden" value="<?php 
            echo $total_satu_bulk * $objb['qty'];
            ?>
" id="subtotalhide_bulk_<?php 
            echo $numb;
            ?>
">
        <td class="rp" id="subtotal_bulk_<?php 
            echo $numb;
            ?>
">
            
            Rp.<?php 
            echo rupiah($total_satu_bulk * $objb['qty']);
            ?>
        </td>
    </tr>
            <?php 
            $totalanb += $total_satu_bulk * $objb['qty'];
            $totalberat += $beratpaket * $objb['qty'];
        }
        $totalan = $totalanb;
        //simpan berat bulk
        ?>
    <input type="hidden" value="<?php 
        echo $totalberat - $this->beratkardus;
        ?>
" id="beratbulk">   
    <input type="hidden" value="<?php 
        echo $totalanb;
        ?>
" id="hargabulk"> 
        <?php 
        //$no = 0;
        //$totalan=0;
        $beratretail = 0;
        foreach ($arr as $num => $obj) {
            $pid = $obj['id'];
            if ($pid == "" || $pid < 1) {
                continue;
            }
            $no++;
            $p = new ProdModel();
            $p->getByID($pid);
            if ($p->prod_diskon > 0) {
                $hrgbaru = ceil((100 - $p->prod_diskon) / 100 * $p->prod_price);
            } else {
                $hrgbaru = $p->prod_price;
            }
            $hrgbaru = $p->prod_satuan_price;
            $totalan += $hrgbaru * $obj['qty'];
            $src = Pwa::getMainPic($p);
            //obj
            $out_of_stock_satuan = 0;
            if (in_array($pid, $arrOOS)) {
                $out_of_stock_satuan = 1;
            }
            //isi berat
            $totalberat += $p->prod_berat_gram * $obj['qty'];
            $beratretail += $p->prod_berat_gram * $obj['qty'];
            ?>
<tr>
    <td><?php 
            echo $no;
            ?>
</td>
    <td><div class="foto100 imageprod prod_<?php 
            echo $p->prod_id;
            ?>
">
        <img  src="<?php 
            echo $src['thumbs'];
            ?>
">
        </div></td>
    
        <td><a target="_blank" href="<?php 
            echo _SPPATH;
            ?>
pwa/p/<?php 
            echo $p->prod_id;
            ?>
/<?php 
            echo urlencode($p->prod_name);
            ?>
">
        <?php 
            echo $p->prod_name;
            ?>
            </a>
            <i title='Remove Item from Cart' onclick="document.location='<?php 
            echo _SPPATH;
            ?>
cartweb/remItem?id=<?php 
            echo $p->prod_id;
            ?>
';" style="cursor: pointer;" class="glyphicon glyphicon-remove"></i>
    </td>
    <td class="rp">Rp.<?php 
            echo rupiah($hrgbaru);
            ?>
</td>
    <td style="text-align: center;">
        
        
        
        <input type="hidden" value="<?php 
            echo $hrgbaru;
            ?>
" id="hargabaru_<?php 
            echo $p->prod_id;
            ?>
">
        <input type="hidden" value="<?php 
            echo $p->prod_berat_gram;
            ?>
" id="beratproduk_<?php 
            echo $p->prod_id;
            ?>
">
        <select id="select_<?php 
            echo $p->prod_id;
            ?>
" >
        <?php 
            for ($x = 1; $x <= $this->max_order_qty_satuan; $x++) {
                ?>
        <option <?php 
                if ($obj['qty'] == $x) {
                    echo 'selected';
                }
                ?>
 value="<?php 
                echo $x;
                ?>
"><?php 
                echo $x;
                ?>
</option>
        <?php 
            }
            ?>
        </select>
        <script>
        $('#select_<?php 
            echo $p->prod_id;
            ?>
').change(function(){
            var slc = $('#select_<?php 
            echo $p->prod_id;
            ?>
').val();
            $('#squaresWaveG').show();
            $.get('<?php 
            echo _SPPATH;
            ?>
CartWeb/addQty?id=<?php 
            echo $p->prod_id;
            ?>
&qty='+slc,function(data){
                //alert(data);
                console.log(data);
                var slc = $('#select_<?php 
            echo $p->prod_id;
            ?>
').val();
                $('#squaresWaveG').hide();
                if(data.bool){
                    $('#out_of_stock').val('0');
                    $('#out_of_stock_alert').hide();
                    $('.imageprod').removeClass('image_oos');
                }else{
                    alert(data.err);
                    $('#out_of_stock_alert').show();
                    $('#out_of_stock').val('1');
                    var arr = data.oos;
                    $('.imageprod').removeClass('image_oos');
                    for(var key=0;key<arr.length;key++){
                        $('.prod_'+arr[key]).addClass('image_oos');
                    }
                }
            },'json');
            var hargabaru = $('#hargabaru_<?php 
            echo $p->prod_id;
            ?>
').val();
                var total = $('#totalAllHide').val();
                var subtotalLama = parseInt($('#subtotalhide_<?php 
            echo $p->prod_id;
            ?>
').val());


                var a = parseInt(slc);
                var harga = parseInt(hargabaru);
                var totalAll = parseInt(total);

                var subtotal = a*harga;
                var diff = subtotal-subtotalLama;
                //console.log(subtotal);
                $('#subtotal_<?php 
            echo $p->prod_id;
            ?>
').html('Rp.'+NilaiRupiah(subtotal)+',-');
                $('#subtotalhide_<?php 
            echo $p->prod_id;
            ?>
').val(subtotal);

                $('#totalAll').html('Rp.'+NilaiRupiah(totalAll+diff)+',-');

                $('#totalAllHide').val(totalAll+diff);
            
                //update berat
                
                var beratproduk = parseInt($('#beratproduk_<?php 
            echo $p->prod_id;
            ?>
').val());
                var beratbulk = parseInt($('#beratbulk').val());
                var beratkardus= parseInt($('#beratkardus').val());
                //isi ke tempatnya
                var kg = (beratkardus+beratbulk+(beratproduk*slc))/1000;
                $('#jneweight').html(kg);
                $('#beratretail').val(beratproduk*slc);
                $('#jneweight_hidden').val((beratkardus+beratbulk+(beratproduk*slc)));
                
                //hitung berdasarkan grenze
                var kg_batas = Math.floor(kg)+parseFloat(<?php 
            echo $this->jne_grenze;
            ?>
);
                if(kg>=kg_batas){
                    kg = Math.ceil(kg);
                }else{
                    kg = Math.floor(kg);
                }
                
                //hitung shipping cost
                var jne_kg_price = $('#jneprice_hidden').val();
                $('#totalShipCost').html('<b>Rp.'+NilaiRupiah(jne_kg_price*kg)+',-</b>');
                $('#totalAllPlusShipCost').html('<b>Rp.'+NilaiRupiah(totalAll+diff+(jne_kg_price*kg))+',-</b>');
                
                //for calculate
                $('#totalShipCost_hidden').val(jne_kg_price*kg);
                $('#totalAllPlusShipCost_hidden').val(totalAll+diff+(jne_kg_price*kg));
        });    
        
        
        </script>
        
    </td>
    <input type="hidden" value="<?php 
            echo $hrgbaru * $obj['qty'];
            ?>
" id="subtotalhide_<?php 
            echo $p->prod_id;
            ?>
">
    <td class="rp" id="subtotal_<?php 
            echo $p->prod_id;
            ?>
">Rp.<?php 
            echo rupiah($hrgbaru * $obj['qty']);
            ?>
</td>
</tr>
            <?php 
        }
        ?>
<input type="hidden" value="<?php 
        echo $beratretail;
        ?>
" id="beratretail">
<tr>
    <td colspan="5"></td>
    <input type="hidden" value="<?php 
        echo $totalan;
        ?>
" id="totalAllHide">
    <td class="rp" style="font-weight: bold;" id="totalAll">Rp.<?php 
        echo rupiah($totalan);
        ?>
</td>
</tr>
<?php 
        $totalberat_kg = $totalberat / 1000;
        ?>
<tr >
    <input type="hidden" value="<?php 
        echo $totalberat;
        ?>
" id="jneweight_hidden">
    <input type="hidden" value="<?php 
        echo $totalberat_kg;
        ?>
" id="jneweight_kg_hidden">
    <input type="hidden" value="8000" id="jneprice_hidden">
    <input type="hidden" value="8000" id="jneprice_reg_hidden">
    <input type="hidden" value="15000" id="jneprice_yes_hidden">
    <input type="hidden" value="1" id="jneprice_yes_hidden_exist">
    <input type="hidden" value="<?php 
        echo $out_of_stock;
        ?>
" id="out_of_stock">
    <td colspan="2" style="text-align: center;"><img src="<?php 
        echo _SPPATH;
        ?>
images/gaido.png" height="90px"></td>
    <td colspan="4">Estimated Weight = <span id="jneweight"><?php 
        echo $totalberat_kg;
        ?>
</span> kg <br> Harga Gaido per kg = <span id='jneprice'>Rp.8000,-</span> (<span id="jnecity">Jakarta Pusat</span>)
<!--        <div id="setModeShip_reg">-->
<!--        <input id="radio_reg" type="radio" name="setModeShip" checked onclick="setModeShip('reg');"> REG (Regular)-->
<!--        </div>-->
<!--        <div id="setModeShip_yes">-->
<!--            <input type="radio" name="setModeShip" onclick="setModeShip('yes');"> YES (Yakin Esok Sampai)-->
<!--        </div>-->
    </td>
    
</tr>
<?php 
        $kg_batas = floor($totalberat_kg) + $this->jne_grenze;
        if ($totalberat_kg >= $kg_batas) {
            $totalberat_kg = ceil($totalberat_kg);
        } else {
            $totalberat_kg = floor($totalberat_kg);
        }
        ?>
<tr>
    <td colspan="5"><b>Shipping Cost</b> <i style="color: #ff0000">*akan dihitung ulang setelah anda memilih kota tujuan.</i></td>
    <td class="rp" id="totalShipCost"><b>Rp.<?php 
        echo rupiah(8000 * $totalberat_kg);
        ?>
</b></td>
    <input type="hidden" value="<?php 
        echo 8000 * $totalberat_kg;
        ?>
" id="totalShipCost_hidden">
</tr>
<tr>
    <td colspan="5"><b>Total</b> </td>
    <td class="rp" id="totalAllPlusShipCost"><b>Rp.<?php 
        echo rupiah($totalan + 8000 * $totalberat_kg);
        ?>
</b></td>
    <input type="hidden" value="<?php 
        echo $totalan + 8000 * $totalberat_kg;
        ?>
" id="totalAllPlusShipCost_hidden">
</tr>
</table>  
</div>
<script>

<?php 
        if ($out_of_stock) {
            ?>
    function oos(){
        var data = JSON.parse('<?php 
            echo json_encode($arrOOS);
            ?>
');
        var arr = data;
        $('.imageprod').removeClass('image_oos');
        for(var key=0;key<arr.length;key++){
            $('.prod_'+arr[key]).addClass('image_oos');
        }
    }
    $(document).ready(function(){
        oos();
        //alert('in');
    });
<?php 
        }
        ?>
    
function NilaiRupiah(jumlah)  
{  
    var titik = ".";
    var nilai = new String(jumlah);  
    var pecah = [];  
    while(nilai.length > 3)  
    {  
        var asd = nilai.substr(nilai.length-3);  
        pecah.unshift(asd);  
        nilai = nilai.substr(0, nilai.length-3);  
    }  

    if(nilai.length > 0) { pecah.unshift(nilai); }  
    nilai = pecah.join(titik);
    return nilai;  
}
function updateCost(){
    var total = parseInt($('#totalAllHide').val());
    var kg = parseInt($('#jneweight_hidden').val())/1000;
    
    //hitung berdasarkan grenze
    var kg_batas = Math.floor(kg)+parseFloat(<?php 
        echo $this->jne_grenze;
        ?>
);
    if(kg>=kg_batas){
        kg = Math.ceil(kg);
    }else{
        kg = Math.floor(kg);
    }
                
     //hitung shipping cost
    var jne_kg_price = $('#jneprice_hidden').val();
    //for showing
    $('#totalShipCost').html('<b>Rp.'+NilaiRupiah(jne_kg_price*kg)+',-</b>');    
    $('#totalAllPlusShipCost').html('<b>Rp.'+NilaiRupiah(total+(jne_kg_price*kg))+',-</b>');
    //for calculate
    $('#totalShipCost_hidden').val(jne_kg_price*kg);
    $('#totalAllPlusShipCost_hidden').val(total+(jne_kg_price*kg));
}
var mode_jne = "reg";
function setModeShip(mode){
    if(mode == "yes"){
        var jne_yes_price = $('#jneprice_yes_hidden').val();
        $('#jneprice_hidden').val(jne_yes_price);
        $('#jneprice').html('Rp.'+NilaiRupiah(jne_yes_price)+',-');
    }
    if(mode == "reg"){
        var jne_reg_price = $('#jneprice_reg_hidden').val();
        $('#jneprice_hidden').val(jne_reg_price);
        $('#jneprice').html('Rp.'+NilaiRupiah(jne_reg_price)+',-');
    }
    mode_jne = mode;
    updateCost();
}
    </script>
        <?php 
    }
    public function details()
    {
        $po = addslashes($_GET['po']);
        if ($po < 1 || $po == "") {
            die("Hacking Attempt");
        }
        $CartModel = new CartModel();
        $CartModel->getByID($po);
        if (!Role::hasRole('admin')) {
            if (Account::getMyID() != $CartModel->userid) {
                die('Hacking Attempt');
            }
        }
        ?>

<html>
<head>
	<meta charset="UTF-8">
	<title>PO Nr.<?php 
        echo $CartModel->po_id;
        ?>
</title>


	<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'
	      name='viewport'>
	<link href="<?php 
        echo _SPPATH;
        echo _THEMEPATH;
        ?>
/css/bootstrap.min.css"
	      rel="stylesheet">
	<link rel="icon"
	      type="image/png"
	      href="<?php 
        echo _SPPATH;
        ?>
kcfinder/favicon.ico" />
	<!--set all paths as javascript-->

	<script src="<?php 
        echo _SPPATH;
        ?>
js/jquery-1.11.1.js"></script>

	<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
	<![endif]-->
	<?php 
        //load default css
        Mold::theme("css");
        //PortalTemplate::headercss();
        ?>
	<style>
		<?php 
        //load custon css
        echo ThemeReg::mod("custom_css", "", "text");
        ?>
                .order_detail{
                    padding-bottom: 5px;
                    font-size: 15px;
                    text-align: right;
                }
                .rp{
                    text-align: right
                }
                h3{
                    padding-top:30px;
                }
	</style>
</head>
<body>
 <div id="holderall"
     class="container">
	<div id="lw_content"></div>

	<div id="content_utama">

		<h1 class="beli" style="text-align: center; padding-bottom: 30px;">
                    <img src="<?php 
        echo _SPPATH;
        ?>
images/belicom-trans.png" height="40px" align="absmiddle"> &nbsp;
                    PO Nr.<?php 
        echo $CartModel->po_id;
        ?>
</h1>
<div class="col-md-8 col-md-offset-2 ">
    <div class="bb" style="padding-left: 30px; padding-right: 30px; padding-bottom: 30px;">

        <div class="order_detail">
            Order ID : <?php 
        echo $CartModel->po_id;
        ?>
        </div>
         <div class="order_detail">
             Order Date : <?php 
        echo indonesian_date($CartModel->po_date);
        ?>
        </div>


        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>Nr.</th>
                    <th>Items</th>
                    <th>Qty</th>
                    <th>Harga</th>
                </tr>
            </thead>

                    <?php 
        $nr = 0;
        $arrbulk = json_decode($CartModel->po_pesanan_bulk);
        foreach ($arrbulk as $bulk) {
            $nr++;
            $ids = $bulk->id;
            $qty = $bulk->qty;
            $imp = explode(",", $ids);
            ?>
<tr>
                                <td><?php 
            echo $nr;
            ?>
</td>
                                <td><?php 
            $hargabulk = 0;
            foreach ($imp as $prod_id) {
                $p = new ProdModel();
                $p->getByID($prod_id);
                echo $p->prod_name . "<br>";
                $hargabulk += $p->prod_bulk_price;
            }
            ?>
                                </td>
                                <td><?php 
            echo $qty;
            ?>
</td>
                                <td class="rp">Rp.<?php 
            echo rupiah($hargabulk * $qty);
            ?>
</td>
                            </tr>
                               <?php 
        }
        $arrretail = json_decode($CartModel->po_pesanan_retail);
        //pr($arrretail);
        foreach ($arrretail as $bulk) {
            $nr++;
            $ids = $bulk->id;
            $qty = $bulk->qty;
            $p = new ProdModel();
            $p->getByID($ids);
            ?>
                            <tr>
                                <td><?php 
            echo $nr;
            ?>
</td>
                                <td><?php 
            echo $p->prod_name;
            ?>
                                </td>
                                <td><?php 
            echo $qty;
            ?>
</td>
                                <td class="rp">Rp.<?php 
            echo rupiah($p->prod_satuan_price * $qty);
            ?>
</td>
                            </tr>
                               <?php 
        }
        ?>

                            <tr>
                                <td colspan="3">

                                </td>
                                <td class="rp">Rp.<?php 
        echo rupiah($CartModel->total_goodcost);
        ?>
</td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    Shipping Cost (JNE <?php 
        echo strtoupper($CartModel->jne_type);
        ?>
)
                                </td>
                                <td class="rp">Rp.<?php 
        echo rupiah($CartModel->total_shipcost);
        ?>
</td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    Total Cost
                                </td>
                                <td class="rp">Rp.<?php 
        echo rupiah($CartModel->total_cost);
        ?>
</td>
                            </tr>
        </table>
        <h3>Penerima</h3>
        <table class="table table-bordered">
            <tr>
                <td>Nama</td>
                <td><?php 
        echo $CartModel->po_name;
        ?>
</td>
            </tr>
            <tr>
                <td>HP</td>
                <td><?php 
        echo $CartModel->po_mobile;
        ?>
</td>
            </tr>
            <tr>
                <td>Alamat</td>
                <td><?php 
        echo $CartModel->po_address;
        ?>
</td>
            </tr>

            <tr>
                <td>Kota</td>
                <td><?php 
        echo $CartModel->city;
        ?>
</td>
            </tr>
            <tr>
                <td>Propinsi</td>
                <td><?php 
        $prop = $CartModel->prop;
        $lok = new LokasiIndoModel();
        $arrp = $lok->getWhere("lokasi_propinsi='{$prop}' and lokasi_kabupatenkota=0 and lokasi_kecamatan=0 and lokasi_kelurahan=0");
        echo $arrp[0]->lokasi_nama;
        ?>
</td>
            </tr>
        </table>
        <h3>Pengirim</h3>
        <table class="table table-bordered">
            <tr>
                <td>Nama</td>
                <td><?php 
        echo $CartModel->pengirim_name;
        ?>
</td>
            </tr>
            <tr>
                <td>HP</td>
                <td><?php 
        echo $CartModel->pengirim_mobile;
        ?>
</td>
            </tr>

        </table>
    </div>


</div>
<div class="clearfix"></div>
	</div>
</div>

    </body>
</html>


         <?php 
    }
    public function addStok()
    {
        $p = new ProdModel();
        $all = $p->getWhere("prod_active = 1");
        ?>
<div class="table-responsive">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Prod ID</th>
                <th>Prod Name</th>
                <th>Stok</th>
                <th>Action</th>
            </tr>
        </thead>
        <?php 
        foreach ($all as $p) {
            ?>
        <tr>
            <td><?php 
            echo $p->prod_id;
            ?>
</td>
            <td><?php 
            echo $p->prod_name;
            ?>
</td>
            <td><?php 
            echo $p->prod_stock;
            ?>
</td>
            <td>
                <input id="stock_<?php 
            echo $p->prod_id;
            ?>
" type="number" value="0"><br>
                <input id="note_<?php 
            echo $p->prod_id;
            ?>
" type="text" placeholder="note"><br>
                <button id="add_stock_<?php 
            echo $p->prod_id;
            ?>
">Add Stok</button>
            </td>
        <script>
        $('#add_stock_<?php 
            echo $p->prod_id;
            ?>
').click(function(){
            var nr = $('#stock_<?php 
            echo $p->prod_id;
            ?>
').val();
            var note = $('#note_<?php 
            echo $p->prod_id;
            ?>
').val();
            if(note!=""){
            $.post('<?php 
            echo _SPPATH;
            ?>
CustomPO/updateStok?pid=<?php 
            echo $p->prod_id;
            ?>
',{note:note,nr:nr},function(data){
                    if(data.bool){
                        alert('Sukses');
                        lwrefresh('Add_Stok');
                    }else{
                        alert('Gagal');
                    }
                },'json');
            }else{
                alert('note tidak boleh kosong');
            }
        });    
        </script>
        </tr>
        <?php 
        }
        ?>
    </table>
</div>    
            
        <?php 
    }