Example #1
0
 /**
  * Mendapatkan Total Stock
  * @param $stockId
  *
  * @return mixed
  */
 public static function getTotalStockFromStockId($stockId)
 {
     if (static::isStockAlreadyExist($stockId)) {
         return Stockproducts::whereId($stockId)->pluck('total');
     }
     return false;
 }
Example #2
0
 public static function generateSampleProducts($count = 10)
 {
     //		Type
     $typeIds = Producttype::getIdsOrCreateDummy();
     //		category
     $categoryIds = Productcategory::getIdsOrCreateSampelData();
     //		unit berat
     $unitIds = Units::getIdsOrCreateSampleUnits();
     //		parent_id
     $parentId = 0;
     $fake = static::getFake();
     //
     //		Buat Product
     $catId = $fake->getFake()->randomElement($categoryIds);
     $typeId = $fake->getFake()->randomElement($typeIds);
     $unitWeightId = $fake->getFake()->randomElement($unitIds);
     $unitWidthId = $fake->getFake()->randomElement($unitIds);
     $supplierIds = Suppliers::getRecordIdsOrCreate();
     $currencyIds = Currencies::getIdsOrCreateSample();
     //		color
     $colorIds = Colors::getIdsOrCreate();
     //  gradeIds
     $gradeIds = Fabricgrade::getIdsOrCreate();
     $productIds = array();
     for ($rec = 0; $rec < $count; $rec++) {
         $product = $fake->getProduct()->product($catId, $typeId, $unitWeightId, $unitWidthId, $parentId, '\\Emayk\\Ics\\Repo\\Productcategory\\Productcategory');
         $record = static::createRecord($product);
         $productId = $record->id;
         $productIds[] = $productId;
         //		Image/ Photo Product
         $imagesIds[] = Images::getIdsOrCreate($productId, '\\Emayk\\Ics\\Repo\\Products\\Products');
         //			Supplier Product
         //		Product Supplier (Product dapat dari Supplier mana ?)
         $supplierId = $fake->getFake()->randomElement($supplierIds);
         $supplierProduct = Productsuppliers::create(array('master_product_id' => $productId, 'master_supplier_id' => $supplierId));
         $supplierProductId = $supplierProduct->id;
         //			Create Detail
         //		Buat Product Detail
         $unitId = $fake->getFake()->randomElement($unitIds);
         $colorId = $fake->getFake()->randomElement($colorIds);
         $gradeId = $fake->getFake()->randomElement($gradeIds);
         $currSp = $fake->getFake()->randomElement($currencyIds);
         $currSpm = $fake->getFake()->randomElement($currencyIds);
         $detailIds[] = Productdetails::getIdOrCreate($productId, $colorId, $unitId, $gradeId, $currSp, $currSpm);
         //Buat Stock
         //		Buat Stock
         $stockIds[] = Stockproducts::createStock($productId);
     }
     foreach ($stockIds as $stockId) {
         for ($history = 0; $history < 9; $history++) {
             //		Buat Stock Detail/History
             if ($history % 2 == 0 || $history == 0) {
                 $typeHistory = 'in';
             } else {
                 $typeHistory = 'out';
             }
             $firstHistory = $history == 0;
             //                $stockHistoryIds[] =
             Stockproducthistory::createHistoryStockSample($stockId, $typeHistory, $firstHistory);
         }
     }
     return "Sudah Generate sebanyak " . count($productIds) . " records";
     return s($productIds, $supplierProductId, $imagesIds, $detailIds);
 }
Example #3
0
File: test.php Project: emayk/ics
 });
 Route::get('stockhistory', function () {
     $stockId = 1;
     $total = \Emayk\Ics\Repo\Stockproducts\Stockproducts::whereId($stockId)->pluck('total');
     return $total;
     $stock = \Emayk\Ics\Repo\Stockproducts\Stockproducts::find($stockId);
     $stock->total = 0;
     $stock->save();
     $stockHistories = \Emayk\Ics\Repo\Stockproducthistory\Stockproducthistory::whereStockId($stockId);
     if ($stockHistories->count()) {
         $ids = $stockHistories->lists('id');
         foreach ($ids as $shId) {
             \Emayk\Ics\Repo\Stockproducthistory\Stockproducthistory::destroy($shId);
         }
         /*Update Stock Id ke 0*/
         $stock = \Emayk\Ics\Repo\Stockproducts\Stockproducts::find($stockId);
         $stock->total = 0;
         $stock->save();
     }
     for ($history = 0; $history < 9; $history++) {
         //		Buat Stock Detail/History
         if ($history % 2 == 0 || $history == 0) {
             $typeHistory = 'in';
         } else {
             $typeHistory = 'out';
         }
         $firstHistory = $history == 0;
         \Emayk\Ics\Repo\Stockproducthistory\Stockproducthistory::createHistoryStockSample($stockId, $typeHistory, $firstHistory);
     }
     return "Done " . time();
 });