/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Warehouse(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Warehouse'])) { $model->attributes = $_POST['Warehouse']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('index', array('model' => $model)); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $rules = array("warehouseId" => "required", "warehouseName" => "required", "firstAddress" => "required", "area" => "required", "region" => "required", "warehousePhone" => "required|numeric", "warehouseFax" => "required|numeric", "warehouseEmail" => "required|email", "warehousePIC" => "required"); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/warehouse/create')->withErrors($validator); } // $warehouse = new Warehouse(); $warehouse->warehouseID = Input::get('warehouseId'); $warehouse->warehouseName = Input::get('warehouseName'); $warehouse->warehouseAddress1 = Input::get('firstAddress'); $warehouse->warehouseAddress2 = Input::get('secondAddress'); $warehouse->areaID = Input::get("area"); $warehouse->regionID = Input::get("region"); $warehouse->warehousePhone = Input::get("warehousePhone"); $warehouse->warehouseFax = Input::get("warehouseFax"); $warehouse->warehouseEmail = Input::get("warehouseEmail"); $warehouse->warehousePIC = Input::get("warehousePIC"); $warehouse->save(); return Redirect::to('/warehouse'); }
/** * postModal (入库确认) */ public function postModal() { //itemReceivedPackageDetail->id $id = Input::get('id'); $position = Input::get('readyposition'); $itemReceivedPackageDetail = ItemReceivedPackageDetail::find($id); $itemReceivedPackageDetail->status = 2; $itemReceivedPackageDetail->readyposition = $position; $itemReceivedPackageDetail->save(); //历史入库记录 $historyWareHouse = new HistoryWarehouse(); $historyWareHouse->identity = $itemReceivedPackageDetail->identity; $historyWareHouse->item = $itemReceivedPackageDetail->item; $historyWareHouse->batch = $itemReceivedPackageDetail->batch; $historyWareHouse->quantity = $itemReceivedPackageDetail->quantity; $historyWareHouse->position = $position; $historyWareHouse->operator = 5; $historyWareHouse->save(); //库存汇总 $wareHouse = Warehouse::where('item', $itemReceivedPackageDetail->item)->where('position', $position)->first(); if ($wareHouse) { $wareHouse->quantity = $wareHouse->quantity + $itemReceivedPackageDetail->quantity; $wareHouse->save(); } else { $wareHouse = new Warehouse(); $wareHouse->item = $itemReceivedPackageDetail->item; $wareHouse->position = $position; $wareHouse->quantity = $itemReceivedPackageDetail->quantity; $wareHouse->save(); } //更新item总库存 $items = Item::where('code', $itemReceivedPackageDetail->item)->first(); $items->stock += $itemReceivedPackageDetail->quantity; $items->readystock -= $itemReceivedPackageDetail->quantity; $items->save(); return Redirect::back(); }
public function postWarehouseAdd() { $validator = Validator::make(Input::all(), Warehouse::$rules); if ($validator->fails()) { return Redirect::to('goods/warehouse-add')->withErrors($validator)->withInput(); } $warehouse = new Warehouse(); $warehouse->name = Input::get('name'); $warehouse->user_id = Input::get('user_id'); $warehouse->save(); return Redirect::to('goods/warehouse-all')->with('success', '仓库添加成功!'); }
/** * postPackageCheckedin (拆包检验入库) */ public function postPackageCheckedin() { $id = Input::get('id'); $position = Input::get('readyposition'); $itemReceivedPackageDetail = ItemReceivedPackageDetail::find($id); $itemReceivedPackageDetail->status = 2; $itemReceivedPackageDetail->readyposition = $position; $itemReceivedPackageDetail->save(); //历史入库记录 $historyWareHouse = new HistoryWarehouse(); $historyWareHouse->identity = $itemReceivedPackageDetail->identity; $historyWareHouse->item = $itemReceivedPackageDetail->item; $historyWareHouse->batch = $itemReceivedPackageDetail->batch; $historyWareHouse->quantity = $itemReceivedPackageDetail->quantity; $historyWareHouse->position = $position; $historyWareHouse->operator = 5; $historyWareHouse->save(); //库存汇总 $wareHouse = Warehouse::where('item', $itemReceivedPackageDetail->item)->where('position', $position)->first(); if ($wareHouse) { $wareHouse->quantity = $wareHouse->quantity + $itemReceivedPackageDetail->quantity; $wareHouse->save(); } else { $wareHouse = new Warehouse(); $wareHouse->item = $itemReceivedPackageDetail->item; $wareHouse->position = $position; $wareHouse->quantity = $itemReceivedPackageDetail->quantity; $wareHouse->save(); } //更新item总库存 $items = Item::where('code', $itemReceivedPackageDetail->item)->first(); $items->stock += $itemReceivedPackageDetail->quantity; $items->readystock -= $itemReceivedPackageDetail->quantity; $items->save(); //到包日期|包号 $itemReceivedPackage = ItemReceivedPackage::find($itemReceivedPackageDetail->package_id); $package_checked_date = $itemReceivedPackage->package_checked_date; $package_no = $itemReceivedPackage->package_no; //供应商 $supplier = Supplier::find($itemReceivedPackageDetail->supplier_id); //details $itemReceivedPackageDetails = ItemReceivedPackageDetail::where('package_id', $itemReceivedPackageDetail->package_id)->orderBy('status')->get(); return View::make('admin.itemreceive.packagedetail')->with('itemReceivedPackageDetails', $itemReceivedPackageDetails)->with('supplier', $supplier)->with('package_checked_date', $package_checked_date)->with('package_no', $package_no); }
private function import() { $db = new PDO(Yii::app()->params['db']['connectionString'], Yii::app()->params['db']['username'], Yii::app()->params['db']['password'], array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING)); $resultRows = $db->query('SELECT * FROM raw_import WHERE id > ' . $this->lastRowProcessed . ' LIMIT ' . $this->rowsToProcess); $suppressionCount = 0; echo "\n\n" . 'Pointer is at ' . $this->lastRowProcessed . "\n\n"; while ($data = $resultRows->fetch(PDO::FETCH_ASSOC)) { $StoreView = null; $DupeMatch = null; $CodeMatch = null; $Store2Contact = null; //20532 // 1 yes 0 no 2 unknown $contact_email = 2; //unkown $contact_post = 2; $contact_sms = 2; $organisation_id = null; // create base Store instance. $StoreView = new Store(); $data['CCR_Client_URN'] = $this->emptyToNull($data['CCR_Client_URN']); if (is_null($data['CCR_Client_URN'])) { // no URN no insert continue; } $StoreView['origin_unique_id'] = trim($data['CCR_Client_URN']); $StoreView['csv_file_uuid'] = $data['Cleaning_UUID']; $StoreView['date_imported'] = date('Y-m-d H:i:s'); //Get organisation id switch ($data['CCR_Organisation']) { case 'Example 1': $organisation_id = 1; switch ($data['CCR_Email_Allow']) { case 'Allow': $contact_email = 1; break; case 'Do Not Allow': $contact_email = 0; break; } break; default: break; } $StoreView['contact_email'] = $contact_email; $StoreView['contact_sms'] = $contact_sms; $StoreView['contact_post'] = $contact_post; $StoreView['origin_organisation_id'] = $organisation_id; $StoreView['salutation'] = $this->emptyToNull($data['CCR_Title']); $StoreView['first_name'] = $this->emptyToNull($data['CCR_Forename']); $StoreView['last_name'] = $this->emptyToNull($data['CCR_Surname']); if (!is_null($StoreView['last_name'])) { $StoreView['last_name'] = rtrim(mcrypt_decrypt($this->cipher, $this->key3, base64_decode($StoreView['last_name']), $this->mode, $this->iv)); } $StoreView['address_line_1'] = $this->emptyToNull($data['CCR_Address1']); if (!is_null($StoreView['address_line_1'])) { $StoreView['address_line_1'] = rtrim(mcrypt_decrypt($this->cipher, $this->key2, base64_decode($StoreView['address_line_1']), $this->mode, $this->iv)); } $StoreView['address_line_2'] = $this->emptyToNull($data['CCR_Address2']); $StoreView['address_line_3'] = $this->emptyToNull($data['CCR_Address3']); $StoreView['address_line_4'] = $this->emptyToNull($data['CCR_Address4']); $StoreView['address_town'] = $this->emptyToNull($data['CCR_Town']); $data['CCR_Postcode'] = trim($data['CCR_Postcode']); if ($this->isPostcode($data['CCR_Postcode'])) { $StoreView['address_postcode'] = $data['CCR_Postcode']; } else { $StoreView['address_postcode'] = null; } $StoreView['address_county'] = $this->emptyToNull($data['CCR_County']); // phone and mobile //regex to to see if provided phone number is mobile $phone1 = intval(rtrim(mcrypt_decrypt($this->cipher, $this->key4, base64_decode($data['CCR_Phone1']), $this->mode, $this->iv))); $phone2 = intval(rtrim(mcrypt_decrypt($this->cipher, $this->key5, base64_decode($data['CCR_Phone2']), $this->mode, $this->iv))); if ($phone1 && $phone2) { if ($this->isMobile($phone1)) { $StoreView['mobile'] = $phone1; $StoreView['phone'] = $phone2; } if ($this->isMobile($phone2)) { $StoreView['mobile'] = $phone2; $StoreView['phone'] = $phone1; } } else { if ($phone1) { if ($this->isMobile($phone1)) { $StoreView['mobile'] = $phone1; } else { $StoreView['phone'] = $phone1; } } else { if ($phone2) { if ($this->isMobile($phone2)) { $StoreView['mobile'] = $phone2; } else { $StoreView['phone'] = $phone2; } } } } // end phone and mobile // email $StoreView->email = $data['CCR_Email']; if (!is_null($StoreView->email)) { $StoreView->email = rtrim(mcrypt_decrypt($this->cipher, $this->key1, base64_decode($StoreView['email']), $this->mode, $this->iv)); } if (!is_null($StoreView['email']) && !filter_var($StoreView->email, FILTER_VALIDATE_EMAIL)) { $StoreView->email = null; } // end email // Save the contact in the store if (!$StoreView->validate()) { print '$StoreView->errors:' . "\n"; print_r($StoreView->errors); } else { $this->totalImported++; //in dupe set $data['CCR_Ind_Set'] = (int) trim($data['CCR_Ind_Set']); /* if(this row has (int)CCR_Ind_Set > 0){ select existing 1+ duplicates if(this row (int)CCR_Ind_Set matches a ccr_duplicate_id with the same organisation_id){ // mega dupe if( existing record has 'Yes' for CCR_Ind_Dupe1 ){ insert and expire this row } else { expire existing insert this row } } else { // no other rows in same org insert this row } } else { // not a duplicate } */ // is this the ccr dupe favoured row? $StoreView['ccr_ind_dupe1'] = trim($data['CCR_Ind_Dupe1']) === 'Yes' ? 1 : 0; // If CCR has detected a duplicate... if ($data['CCR_Ind_Set'] > 0) { $this->totalDupes++; $StoreView->ccr_duplicate_id = $data['CCR_Ind_Set']; //print "CCR_Ind_Set > 0\n"; //first of all, let see if the dupe has the same origin id as a previous in the database $DupeMatches = Store::model()->with(array('store2contact'))->findAllByAttributes(array('ccr_duplicate_id' => $data['CCR_Ind_Set'], 'date_expired' => null), array('index' => 'origin_organisation_id')); // print ('starting new loop with dupes'); if (sizeof($DupeMatches)) { // print "size DupeMatches > 0\n"; $Store2Contact = null; // print_r(array_keys($DupeMatches)); // print "\nDupeMatch orgs: " . $organisation_id . "\n"; if (array_key_exists((int) $organisation_id, $DupeMatches)) { // we have a match from the same organisation // print "org exists in dupes data\n"; //not do in the correct order, needs to be done with CCR_Ind_Set //we need to expire the match and update the warehouse record //we the new one //echo 'DupeMatch'; if ($DupeMatches[$organisation_id]->ccr_ind_dupe1) { // print "Alread have trusted row, expire row\n"; // already have a trusted row. Expire and insert this one. $StoreView->date_expired = date('Y-m-d H:i:s'); $StoreView->ccr_ind_dupe1 = 0; // just in case. } else { // print "Update store row\n"; // update store row $DupeMatches[$organisation_id]->date_expired = date('Y-m-d H:i:s'); $DupeMatches[$organisation_id]->save(); // update any suppression list rows to not have warehouse or store_id. They're old and expired. SuppressionList::model()->deleteAll('store2contact_id = ' . (int) $DupeMatches[$organisation_id]->store2contact->id); // clone the contact_warehouse_id and ind set. Gets saved below. $Store2Contact = $DupeMatches[$organisation_id]->store2contact; // print 'Store2Contact='; // print_r ($Store2Contact->attributes); $Store2Contact->contact_warehouse_id = $DupeMatches[$organisation_id]->store2contact->contact_warehouse_id; } } else { // print "org does not exist in dupes data\n"; //is it not a dupe match but someone else has the same dupe id? //if so, lets find their Warehouse ID and then add as a new row $LastDuplicate = end($DupeMatches); $Store2Contact = new Store2Contact(); $Store2Contact->contact_warehouse_id = $LastDuplicate->store2contact->contact_warehouse_id; } // the save for dupes is here if (!$StoreView->save()) { print_r($StoreView->errors); } // if we have a store2contact save it here if (!is_null($Store2Contact)) { //update store_id to new one $Store2Contact->store_id = $StoreView->id; $Store2Contact->origin_unique_id = $data['CCR_Client_URN']; $Store2Contact->origin_id = $organisation_id; // print 'saving a (dupe style) store2contact ' . $Store2Contact->id . "\n"; if (!$Store2Contact->save()) { print_r($Store2Contact->errors); } } // currently required below. //unset($Store2Contact); } } // when not a duplicate or there is no other dupe stored yet if ($data['CCR_Ind_Set'] == 0 || !sizeof($DupeMatches)) { // save for when no duplicates if (!$StoreView->save()) { print_r($StoreView->errors); } $Warehouse = new Warehouse(); if (!$Warehouse->save()) { print_r($Warehouse->errors); } // Create a new Store2Contact row $Store2Contact = new Store2Contact(); $Store2Contact->store_id = $StoreView->id; $Store2Contact->contact_warehouse_id = $Warehouse->id; $Store2Contact->origin_unique_id = $data['CCR_Client_URN']; $Store2Contact->origin_id = $organisation_id; if (!$Store2Contact->save()) { print_r($Store2Contact->errors); } } // Check for non-contactable by email, and add to the supression list if ($StoreView->contact_email == 0) { if (!is_null($Store2Contact) && (int) $Store2Contact->id) { $Suppression = new SuppressionList(); $Suppression->type = SuppressionList::TYPE_UNSUBSCRIBE; // always save the store id against this row $Suppression->store_id = $StoreView->id; // we have a store2contact row for this person. Add to suppression data. $Suppression->store2contact_id = $Store2Contact->id; //We don't need the warehouse id //$Suppression->warehouse_id = $Store2Contact->contact_warehouse_id; $Suppression->date = date('Y-m-d H:i:s'); if ($Suppression->save()) { $suppressionCount++; } } } } unset($data); unset($StoreView); unset($Store2Contact); unset($DupeMatch); unset($CodeMatch); $this->lastRowProcessed++; if (!($this->lastRowProcessed % 100)) { $this->completedToNow = $this->lastRowProcessed; $timeTotal = microtime(true) - $this->time_start; $timeForThis100 = $timeTotal - $this->timeTakenSoFar; $this->timeTakenSoFar = $timeTotal; $speed = round(1 / $timeForThis100 * 100, 3); $currentExecutionTime = round($timeTotal / 60, 2); echo $this->lastRowProcessed / 1000 . 'k done in ' . $currentExecutionTime . ' mins. ' . $speed . ' rows/s ' . "\r"; } } print "\n\n" . $suppressionCount . ' contacts were added to suppression list - not contactable by email' . "\n\n"; }
public function actionStepOne() { $this->inAccession = true; // Have we arrived here with an accession hash, allowing us to track this contact through accession? if (isset($_GET['accessionhash'])) { $Accession = $this->getAccessionRecord(); $this->checkStep($Accession, 1); } else { $Accession = new Accession(); $Accession->step = 1; } $this->pageTitle = 'Welcome to ' . Yii::app()->name . ' | Step One | Accession'; if (isset($_POST['Accession'])) { if ($_POST['Accession']['terms_agreed'] === '1') { // Accession hash will be null if they've signed up from the public link if (is_null($Accession->accession_hash)) { $Accession->accession_hash = sha1(rand(1, 99999) . microtime(true)); } // TERMS ARE AGREED! We're good to go. Set up all the models $Accession->terms_agreed = date('Y-m-d H:i:s'); if (!$Accession->save()) { print_r($Accession->errors); exit; } // Now they've agreed terms, update the invite (if they had one) if ($Accession->invite_id) { $Invite = Invite::model()->findByPk($Accession->invite_id); if (!is_null($Invite)) { $Invite->status = Invite::STATUS_ACCEPTED; $Invite->save(true, array('status')); } } $new = false; // If it's a new contact coming to the list, we just have a blank row // If they've come via an invite then we copy their Store row if (is_null($Accession->original_store2contact_id)) { // This contact is new $Store = new Store(); // Create a new warehouse row $Warehouse = new Warehouse(); $Warehouse->save(); // Set the warehouse id to the accession model $Accession->warehouse_id = $Warehouse->id; $Accession->save(true, array('warehouse_id')); $new = true; } else { // This contact came from an invite // Grab their previous data $Store2Contact = Store2Contact::model()->findByPk($Accession->original_store2contact_id); // Get the contact's warehouse_id - this identifies them uniquely, even if they have multiple instances in Store $Warehouse = Warehouse::model()->findByPk($Store2Contact->contact_warehouse_id); $ExistingStore = Store::model()->findByPk($Store2Contact->store_id); // Now make a new store to duplicate their info to $Store = new Store(); $Store->attributes = $ExistingStore->attributes; $Store->id = null; } // Set the org ID to THE LIST $Store->origin_organisation_id = 10; // Try to save the Store if (!$Store->save()) { print 'Store errors:<br>'; print_r($Store->errors); exit; } // Also create a new Store2Contact row $Store2Contact = new Store2Contact(); $Store2Contact->store_id = $Store->id; $Store2Contact->contact_warehouse_id = $Warehouse->id; $Store2Contact->origin_id = 10; if (!$Store2Contact->save()) { print 'Store2Contact errors:<br>'; print_r($Store2Contact->errors); exit; } // Now also save the new Store2Contact ID to Accession $Accession->store2contact_id = $Store2Contact->id; if ($new) { $Accession->original_store2contact_id = $Store2Contact->id; } } if ($Accession->save(true, array('terms_agreed', 'store2contact_id', 'original_store2contact_id'))) { $this->updateStep($Accession, 1); $this->redirect(array('accession/stepTwo', 'accessionhash' => $Accession->accession_hash)); } } $this->render('step1', array('Accession' => $Accession, 'progress' => 1)); }