Khi nhập hàng bạn cần căn cứ vào dữ liệu bán hàng trong 1 tuần trước,2 tuần trước ,3 tuần trước 1 tháng trước .Với tầm 100 mẫu để xử lý bằng excel hay cần kho kiểm đếm sẽ rất lâu
Ở đây mình đã xử lý thông qua đoạn code
Ở trong themes phần header.php
</li> <?php if ($this->Owner || $this->Admin) {?> <li id="products_count_stock"> <a class="submenu" href="<?= admin_url('products/order'); ?>"> <i class="fa fa-plus-circle"></i> <span class="text">Dữ liệu bán hàng </span> </a> </li> <?php } ?>
để gọi Url đến mục order chỉ dành cho admin và quản trị
Ở phần controllers File Products.php
function order() { if ($this->Owner || $this->Admin) { $list_product = $this->products_model->getAllProducts(); $soluongmacannhap = 0; $sotiencanchuanbi= 0; foreach ($list_product as $key => $value) { // trường hợp có biến thể $options = $this->products_model->getProductOptionsWithWH($value->id); $variants = $this->products_model->getProductOptions($value->id); $bienthe =''; if ($variants) { foreach ($options as $option) { $soluongtoithieucannhap = 0; $soluong_hangcon = round($option->wh_qty); $bienthe = $option->name; $sale1tuan = $this->products_model->getSalesItemsbyId_variants($option->id,'week',$option->warehouse_id); $sale2tuan = $this->products_model->getSalesItemsbyId_variants($option->id,'2tuan',$option->warehouse_id); $sale3tuan = $this->products_model->getSalesItemsbyId_variants($option->id,'3tuan',$option->warehouse_id); $sale1thang = $this->products_model->getSalesItemsbyId_variants($option->id,'1thang',$option->warehouse_id); if ($soluong_hangcon == 0) { $soluongtoithieucannhap = $sale2tuan -$soluong_hangcon; $sotiencanchuanbi += $value->cost * $soluongtoithieucannhap; $note = 0; $soluongmacannhap +=1; } elseif($soluong_hangcon >= $sale3tuan) { $note = 3; } elseif($soluong_hangcon >= $sale2tuan) { $note = 2; } elseif($soluong_hangcon >= $sale1tuan){ $soluongtoithieucannhap = $sale2tuan -$soluong_hangcon; $sotiencanchuanbi += $value->cost * $soluongtoithieucannhap; $soluongmacannhap +=1; $note = 1; } else{ $soluongtoithieucannhap = $sale2tuan -$soluong_hangcon; $sotiencanchuanbi += $value->cost * $soluongtoithieucannhap; $soluongmacannhap +=1; $note = 0; } $data_product = array('id'=>$value->id, 'name'=>$value->name, 'name_bienthe'=>$bienthe, 'image'=>$value->image, 'code'=>$value->code, 'quantity'=>$option->quantity, 'cost'=>$value->cost, 'sale1tuan'=>$sale1tuan, 'sale2tuan'=>$sale2tuan, 'sale3tuan'=>$sale3tuan, 'sale1thang'=>$sale1thang, 'sotiencanchuanbi'=>$value->cost * $soluongtoithieucannhap, 'soluongtoithieucannhap' => $soluongtoithieucannhap, 'note'=>$note, ); $data[]= $data_product; } } else{ //$this->data['variants'] = $this->products_model->getProductOptions($id); $soluongtoithieucannhap = 0; $soluong_hangcon = round($value->quantity); $sale1tuan = $this->products_model->getSalesbyId($value->id,'week',$warehouse->id); $sale2tuan = $this->products_model->getSalesbyId($value->id,'2tuan',$warehouse->id); $sale3tuan = $this->products_model->getSalesbyId($value->id,'3tuan',$warehouse->id); $sale1thang = $this->products_model->getSalesbyId($value->id,'month',$warehouse->id); //var_dump($value);die; //echo $soluong_hangcon; //echo $sale1tuan; //echo '<br/>'; //note = 0 nhập hàng 1 bán trong 1 tuần 2 bán trogn 2 tuần if ($soluong_hangcon == 0) { $soluongtoithieucannhap = $sale2tuan -$soluong_hangcon; $sotiencanchuanbi += $value->cost * $soluongtoithieucannhap; $note = 0; $soluongmacannhap +=1; } elseif($soluong_hangcon >= $sale3tuan) { $note = 3; } elseif($soluong_hangcon >= $sale2tuan) { $note = 2; } elseif($soluong_hangcon >= $sale1tuan){ $soluongtoithieucannhap = $sale2tuan -$soluong_hangcon; $sotiencanchuanbi += $value->cost * $soluongtoithieucannhap; $soluongmacannhap +=1; $note = 1; } else{ $soluongtoithieucannhap = $sale2tuan -$soluong_hangcon; $sotiencanchuanbi += $value->cost * $soluongtoithieucannhap; $soluongmacannhap +=1; $note = 0; } $data_product = array('id'=>$value->id, 'name'=>$value->name, 'name_bienthe'=>$bienthe, 'image'=>$value->image, 'code'=>$value->code, 'quantity'=>$value->quantity, 'cost'=>$value->cost, 'sale1tuan'=>$sale1tuan, 'sale2tuan'=>$sale2tuan, 'sale3tuan'=>$sale3tuan, 'sale1thang'=>$sale1thang, 'sotiencanchuanbi'=>$value->cost * $soluongtoithieucannhap, 'soluongtoithieucannhap' => $soluongtoithieucannhap, 'note'=>$note, ); $data[]= $data_product; } } $this->data['soluongmacannhap']= $soluongmacannhap; $this->data['sotiencanchuanbi']=$sotiencanchuanbi; $this->data['data']= $data; $this->load->admin_model('db_model'); $this->data['bs'] = $this->db_model->getBestSeller(); $lmsdate = date('Y-m-d', strtotime('-2 week')) . ' 00:00:00'; $lmedate = date('Y-m-d', strtotime('now')) . ' 23:59:59'; $this->data['lmbs'] = $this->db_model->getBestSeller($lmsdate, $lmedate); $this->data['badseller'] = $this->db_model->getBadSeller($lmsdate, $lmedate,40); $meta = array('page_title' => 'Nhập hàng', 'bc' => $bc); $this->page_construct('products/nhap', $meta, $this->data); } else{ echo 'Bạn không có quyền truy cập vào phần này'; } }
Ở phần view : file nhap.php
<div class="box"> <div class="box-header"> <h2 class="blue"><i class="fa-fw fa fa-plus"></i>Tổng hợp bán hàng theo mã sản phẩm </h2> </div> <div class="box-content"> <div class="col-lg-12 well"> <div class="col-lg-6 "> <h2 class="red">Có <?= $soluongmacannhap?> mã cần nhập</h2> </div> <div class="col-lg-6"> <h2 class="red">Số tiền tối thiểu cần nhập <?= $this->sma->formatMoney($sotiencanchuanbi) ?></h2> </div> </div> <div class="row"> <div class="group-tabs"> <!-- Nav tabs --> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Danh sách bán hàng</a></li> <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Danh sách cần nhập hàng </a></li> <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Sản phẩm bán chạy trong 2 tuần</a></li> <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Sản phẩm tồn cần đẩy </a></li> </ul> <!-- Tab panes --> <div class="tab-content"> <div role="tabpanel" class="tab-pane active" id="home"> <table class="table table-striped table-bordered"> <thead> <tr> <th scope="col">STT</th> <th scope="col">Mã sản phẩm</th> <th scope="col">Ảnh</th> <th scope="col">Tên sản phẩm </th> <th scope="col">Biến thể</th> <th scope="col">Số lượng hiện có</th> <th scope="col">Bán 1 tuần</th> <th scope="col">Bán 2 tuần</th> <th scope="col">Bán 3 tuần</th> <th scope="col">Bán 1 tháng</th> <th scope="col">Note</th> </tr> </thead> <tbody> <?php foreach ($data as $key=>$value) { ?> <?php if($value['note'] <= 1){ echo '<tr style="color: red;">'; } elseif($value['note'] <= 2) echo '<tr style="color: #0044cc;">'; else {echo '<tr>';} ?> <th scope="col"><?= $key ?></th> <th scope="col"><?= $value['code'];?></th> <th scope="col"> <div class="text-center"> <a href="https://quantri.mohinhlaprap3d.com/assets/uploads/<?= $value['image']?>" data-toggle="lightbox"> <img src="https://quantri.mohinhlaprap3d.com/assets/uploads/thumbs/<?= $value['image']?>" alt="" style="width:30px; height:30px;"> </a> </div> </th> <th scope="col"><?= $value['name'];?></th> <th scope="col"><?= $value['name_bienthe'];?></th> <th scope="col"><?= round($value['quantity']);?></th> <th scope="col"><?= $value['sale1tuan'];?></th> <th scope="col"><?= $value['sale2tuan'];?></th> <th scope="col"><?= $value['sale3tuan'];?></th> <th scope="col"><?= $value['sale1thang'];?></th> <th scope="col"><?php if ($value['note'] <=1) { echo 'nhập hàng'; } else{ echo 'chưa cần nhập'; } ?></th> </tr> <?php } ?> </tbody> </table> </div> <div role="tabpanel" class="tab-pane" id="profile"> <table class="table table-striped table-bordered"> <thead> <tr> <th scope="col">STT</th> <th scope="col">Mã sản phẩm</th> <th scope="col">Ảnh</th> <th scope="col">Tên sản phẩm </th> <th scope="col">Biến thể</th> <th scope="col">Số lượng hiện có</th> <th scope="col">Bán 1 tuần</th> <th scope="col">Bán 2 tuần</th> <th scope="col">Bán 3 tuần</th> <th scope="col">Số lượng tối thiểu trong 2 tuần tới </th> <th scope="col">Giá mua</th></th> <th scope="col">Số tiền dự trù</th> </tr> </thead> <tbody> <?php $i= 1;?> <?php foreach ($data as $key=>$value) { ?> <?php if($value['note'] <= 1){?> <th scope="col"><?= $i ?></th> <th scope="col"><?= $value['code'];?></th> <th scope="col"> <div class="text-center"> <a href="https://quantri.mohinhlaprap3d.com/assets/uploads/<?= $value['image']?>" data-toggle="lightbox"> <img src="https://quantri.mohinhlaprap3d.com/assets/uploads/thumbs/<?= $value['image']?>" alt="" style="width:30px; height:30px;"> </a> </div> </th> <th scope="col"><?= $value['name'];?></th> <th scope="col"><?= $value['name_bienthe'];?></th> <th scope="col"><?= round($value['quantity']);?></th> <th scope="col"><?= $value['sale1tuan'];?></th> <th scope="col"><?= $value['sale2tuan'];?></th> <th scope="col"><?= $value['sale3tuan'];?></th> <th scope="col" style="color: red;"><?= $value['soluongtoithieucannhap'];?></th> <th scope="col"><?= $this->sma->formatMoney($value['cost']);?></th> <th scope="col"><?= $this->sma->formatMoney($value['sotiencanchuanbi']);?></th> </tr> <?php $i +=1; } } ?> </tbody> </table> </div> <div role="tabpanel" class="tab-pane" id="messages"> <table class="table table-striped table-bordered"> <thead> <tr> <th scope="col">STT</th> <th scope="col">Mã sản phẩm</th> <th scope="col">Tên sản phẩm </th> <th scope="col">Biến thể </th> <th scope="col">Số lượng bán</th> </tr> </thead> <tbody> <?php foreach ($lmbs as $key=>$value) { ?> <?php if($value->product_code !='SHIP01'){ ?> <tr> <th scope="col"><?= $key ?></th> <th scope="col"><?= $value->product_code?></th> <th scope="col"><?= $value->product_name ?></th> <th scope="col"><?= $value->name_bienthe;?></th> <th scope="col"><?= round($value->quantity) ?></th> </tr> <?php } } ?> </tbody> </table> </div> <div role="tabpanel" class="tab-pane" id="settings"> <table class="table table-striped table-bordered"> <thead> <tr> <th scope="col">STT</th> <th scope="col">Mã sản phẩm</th> <th scope="col">Tên sản phẩm </th> <th scope="col">Số lượng bán</th> </tr> </thead> <tbody> <?php foreach ($badseller as $key=>$value) { ?> <?php if($value->product_code !='SHIP01'){ ?> <tr> <th scope="col"><?= $key ?></th> <th scope="col"><?= $value->product_code?></th> <th scope="col"><?= $value->product_name ?></th> <th scope="col"><?= round($value->quantity) ?></th> </tr> <?php } } ?> </tbody> </table> </div> </div> </div> </div> </div> <div class="col-lg-12"> </div> </div> </div> </div> <script type="text/javascript"> $(document).ready(function() { $('#table').DataTable( { "order": [[ 5, "desc" ]] } ); } ); </script>