Ejemplo n.º 1
0
 if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
     if ($new_timeperiod['month_date_type'] > 0) {
         $new_timeperiod['day'] = 0;
     } else {
         $new_timeperiod['every'] = 0;
         $new_timeperiod['dayofweek'] = 0;
     }
 }
 $_REQUEST['timeperiods'] = get_request('timeperiods', array());
 $result = false;
 if ($new_timeperiod['period'] < 300) {
     info(_('Incorrect maintenance period (minimum 5 minutes)'));
 } elseif ($new_timeperiod['hour'] > 23 || $new_timeperiod['minute'] > 59) {
     info(_('Incorrect maintenance period'));
 } elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
     if (!validateDateTime($_REQUEST['new_timeperiod_start_date_year'], $_REQUEST['new_timeperiod_start_date_month'], $_REQUEST['new_timeperiod_start_date_day'], $_REQUEST['new_timeperiod_start_date_hour'], $_REQUEST['new_timeperiod_start_date_minute'])) {
         error(_('Invalid maintenance period'));
     } elseif (!validateDateInterval($_REQUEST['new_timeperiod_start_date_year'], $_REQUEST['new_timeperiod_start_date_month'], $_REQUEST['new_timeperiod_start_date_day'])) {
         error(_('Incorrect maintenance - date must be between 1970.01.01 and 2038.01.18'));
     } else {
         $result = true;
     }
 } elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY && $new_timeperiod['every'] < 1) {
     info(_('Incorrect maintenance day period'));
 } elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) {
     if ($new_timeperiod['every'] < 1) {
         info(_('Incorrect maintenance week period'));
     } elseif ($new_timeperiod['dayofweek'] < 1) {
         info(_('Incorrect maintenance days of week'));
     } else {
         $result = true;
Ejemplo n.º 2
0
 public function uploadEbaySellOrderFile(array $fileArray)
 {
     $this->load->model('sell_order');
     $fileError = $fileSuccess = array();
     $filePath = $this->uploadFile($fileArray);
     if (count($this->_ebayColumnArray) !== EBAY_COLUMN_COUNT) {
         throw new Exception("System Error: Ebay csv column count is set as [" . EBAY_COLUMN_COUNT . "] but the setup has column count of [" . count($this->_ebayColumnArray) . "]");
     }
     $fp = fopen($filePath, "r");
     if (!$fp) {
         throw new Exception("Unable to read file [" . $filePath . "]");
     }
     $lineCounter = 0;
     while (($data = fgetcsv($fp)) !== false) {
         if (count($data) <= 0 || count($data) !== EBAY_COLUMN_COUNT) {
             continue;
         }
         $lineCounter++;
         if ($lineCounter === 1) {
             continue;
         }
         try {
             $error = array();
             for ($i = 0; $i < count($this->_ebayColumnArray); $i++) {
                 $var = $this->_ebayColumnArray[$i];
                 ${$var} = '';
                 ${$var} = trim($data[$i]);
                 if (in_array($var, $this->_mandatoryEbayColumnArray) && ${$var} === '') {
                     $error[] = "Missing Value for Column [" . $var . "]";
                 }
             }
             if (count($error) > 0) {
                 throw new Exception(implode("<br/>", $error));
             }
             $orderTotalInc = $this->_covertEbayPrice($totalPrice);
             if (!is_numeric($orderTotalInc) || $orderTotalInc <= 0) {
                 throw new Exception('The Sale Price [' . $totalPrice . '] is invalid');
             }
             $postageCostInc = $this->_covertEbayPrice($postageAndHandling);
             $customer = false;
             $state = false;
             $sellSourceId = SELL_SOURCE_EBAY;
             $sellOrderStatusId = SELL_ORDER_STATUS_DISPATCHED;
             $paymentReceivedDate = $paymentMethodId = $paymentReferenceNo = false;
             $sellOrderAddressLine1 = $sellOrderAddressLine2 = $sellOrderPostcode = $sellOrderSuburb = $firstName = $lastName = '';
             $sellOrderState = false;
             $sellOrderPhone = $sellOrderEmail = '';
             $deliveryMethodId = DELIVERY_METHOD_DELIVERY;
             $sellOrderId = false;
             list($firstName, $lastName) = explode(" ", $buyerFullName);
             if ($buyerState !== '') {
                 $stateArray = $this->customer->getStates(array('name like' => $buyerState));
                 if (count($stateArray) > 0) {
                     $state = $stateArray[0];
                 }
             }
             $state = $state !== false ? $state->id : 0;
             /// first check if the sell_order already exists in the system ///
             $existingSellOrder = false;
             $insert = true;
             $esoArray = $this->sell_order->getSellOrders(array('external_identifier' => $saleRecordNumber));
             if (count($esoArray) > 0) {
                 $existingSellOrder = $esoArray[0];
                 $insert = false;
                 $sellOrderId = $existingSellOrder->id;
             }
             //////////////////////////////////////////////////////////////
             if (strtolower($paymentMethod) === 'paypal') {
                 $paymentMethodId = PAYMENT_METHOD_PAYPAL;
                 $paymentReferenceNo = $paypalTransactionId;
             }
             if (validateDateTime($paidOnDate, 'd-M-y')) {
                 $paymentReceivedDate = convertDateTime($paidOnDate);
             }
             $additionalComments = array();
             $additionalComments[] = "Ebay Sell Record No: [" . $saleRecordNumber . "]";
             $additionalComments[] = "Ebay Transaction Id: [" . $transactionId . "]";
             $additionalComments[] = "Ebay Item No: [" . $itemNo . "]";
             $additionalComments[] = "Ebay Item Title: [" . $itemTitle . "]";
             $additionalComments[] = "Ebay Note: [" . $notesToYourself . "]";
             $additionalComments[] = "Ebay Sale Date: [" . $saleDate . "]";
             $additionalComments[] = "Ebay Checkout Date: [" . $checkoutDate . "]";
             $additionalComments[] = "Ebay Click and Collect: [" . $clickAndCollect . "]";
             $additionalComments[] = "Ebay Click and Collect Ref No: [" . $clickAndCollectReferenceNo . "]";
             $additionalComments = implode("<*>", $additionalComments);
             /// figure out the address for the sell order (if required) ///
             $sellOrderAddressLine1 = $postToAddress1 !== '' ? $postToAddress1 : $buyerAddress1;
             $sellOrderAddressLine2 = $postToAddress2 !== '' ? $postToAddress2 : $buyerAddress2;
             $sellOrderSuburb = $postToCity !== '' ? $postToCity : $buyerCity;
             $sellOrderPostcode = $postToPostalCode !== '' ? $postToPostalCode : $buyerPostcode;
             if ($postToState == $buyerState) {
                 $sellOrderState = $state;
             } else {
                 $psArray = $this->customer->getStates(array('name like' => $postToState));
                 if (count($psArray) > 0) {
                     $sellOrderState = $psArray[0];
                 }
                 $sellOrderState = $sellOrderState !== false ? $sellOrderState->id : 0;
             }
             if ($deliveryMethodId == DELIVERY_METHOD_DELIVERY) {
                 if ($sellOrderAddressLine1 == '' && $sellOrderAddressLine2 == '' || $sellOrderPostcode == '' || $sellOrderSuburb == '' || ($sellOrderState == '' || $sellOrderState === false || $sellOrderState == 0)) {
                     throw new Exception("Postal Address is required for this order as the delivery method is marked as [" . $postageService . "]. Address information missing");
                 }
             }
             ///////////////////////////////////////////////////////////////////////////////////////////
             $sellOrderContactNo = $buyerPhone;
             $sellOrderEmail = $buyerEmail;
             $sellOrderCriteria = $customerCriteria = array();
             $customerCriteria = array('first_name' => $firstName, 'last_name' => $lastName, 'phone' => $buyerPhone, 'email' => $buyerEmail, 'ebay_id' => $ebayUserId, 'address_line_1' => $buyerAddress1, 'address_line_2' => $buyerAddress2, 'address_suburb' => $buyerCity, 'address_state_id' => $state, 'address_postcode' => $buyerPostcode);
             $sellOrderCriteria = array('sell_order_status_id' => $sellOrderStatusId, 'sell_source_id' => $sellSourceId, 'external_identifier' => $saleRecordNumber, 'order_total_ex' => '', 'order_total_inc' => $orderTotalInc, 'payment_method_id' => $paymentMethodId, 'payment_reference_no' => $paymentReferenceNo, 'additional_comments' => $additionalComments, 'payment_received_date' => $paymentReceivedDate, 'delivery_method_id' => $deliveryMethodId, 'postage_cost_inc' => $postageCostInc, 'address_line_1' => $sellOrderAddressLine1, 'address_line_2' => $sellOrderAddressLine2, 'suburb' => $sellOrderSuburb, 'state_id' => $sellOrderState, 'postcode' => $sellOrderPostcode, 'product_instances' => array(), 'email' => $sellOrderEmail, 'phone' => $sellOrderPhone);
             if ($insert == true) {
                 $sellOrderId = $this->sell_order->createSellOrder($customerCriteria, $sellOrderCriteria);
             } else {
                 $sellOrderId = $this->sell_order->updateSellOrder($sellOrderId, $updateCriteria);
             }
             if ($sellOrderId === false) {
                 throw new Exception('Cannot Create/Update Sell Order. Unknow Reason....');
             }
         } catch (Exception $ex) {
             $fileError[] = "Ebay Sell List CSV [" . $filePath . "], Line [" . $lineCounter . "] has the following problems:<br/>" . $ex->getMessage();
         }
         echo "<hr/>";
     }
     fclose($fp);
     @unlink($filePath);
     $lineCounter = $lineCounter - 1;
     $output['message'] = "Total Line processed [" . $lineCounter . "]";
     $output['error'] = $fileError;
     return $output;
 }
Ejemplo n.º 3
0
 private function _precheckSellOrderInput(array $option)
 {
     if (!isset($option['customer_id']) || ($option['customer_id'] = trim($option['customer_id'])) === '') {
         $errorArray[] = "A Customer is required to create/update sell order";
     }
     if (!isset($option['sell_source_id']) || ($option['sell_source_id'] = trim($option['sell_source_id'])) === '') {
         $errorArray[] = "A Sell Source is required to create/update sell order";
     }
     if (!isset($option['product_instances']) || !is_array($option['product_instances']) || count($option['product_instances']) <= 0) {
         throw new Exception("Product(s) must be specified to create/update sell order");
     }
     if (!isset($option['sell_order_status_id']) || trim($option['sell_order_status_id']) === '') {
         throw new Exception('A status must be specified to create/update order');
     }
     if (!isset($option['delivery_method_id']) || trim($option['delivery_method_id']) === '') {
         throw new Exception('A Delivery Method must be specified to create/update order');
     }
     if (!isset($option['order_total_ex']) || trim($option['order_total_ex']) === '' || !is_numeric($option['order_total_ex'])) {
         $option['order_total_ex'] = false;
     }
     if (!isset($option['order_total_inc']) || trim($option['order_total_inc']) === '' || !is_numeric($option['order_total_inc'])) {
         $option['order_total_inc'] = false;
     }
     if ($option['order_total_ex'] === false && $option['order_total_inc'] === false) {
         $errorArray[] = 'A sell price must be specified to create/update order';
     } else {
         if ($option['order_total_ex'] === false) {
             getGSTExclusivePrice($option['order_total_inc']);
         } else {
             if ($option['order_total_inc'] === false) {
                 getGSTInclusivePrice($option['order_total_ex']);
             }
         }
     }
     if (!isset($option['payment_method_id']) || ($option['payment_method_id'] = trim($option['payment_method_id'])) === '') {
         $errorArray[] = 'A Payment method must be specified';
     }
     if (isset($option['payment_received_date']) && ($prd = trim($option['payment_received_date'])) !== '' && validateDateTime($prd, 'Y-m-d H:i:s')) {
         $option['payment_received_date'] = $prd;
     } else {
         $option['payment_received_date'] = date('Y-m-d H:i:s');
     }
     $option['address_line_1'] = isset($option['address_line_1']) ? trim($option['address_line_1']) : '';
     $option['address_line_2'] = isset($option['address_line_2']) ? trim($option['address_line_2']) : '';
     $option['suburb'] = isset($option['suburb']) ? trim($option['suburb']) : '';
     $option['postcode'] = isset($option['postcode']) ? trim($option['postcode']) : '';
     $option['state_id'] = isset($option['state_id']) ? trim($option['state_id']) : '';
     $option['email'] = isset($option['email']) ? trim($option['email']) : '';
     $option['contact_no'] = isset($option['contact_no']) ? trim($option['contact_no']) : '';
     $option['consignment_no'] = isset($option['consignment_no']) ? trim($option['consignment_no']) : '';
     $option['payment_reference_no'] = isset($option['payment_reference_no']) ? trim($option['payment_reference_no']) : '';
     $option['additional_comments'] = isset($option['additional_comments']) ? trim($option['additional_comments']) : '';
     $option['external_identifier'] = isset($option['external_identifier']) ? trim($option['external_identifier']) : '';
     $option['postage_cost_inc'] = isset($option['postage_cost_inc']) ? trim($option['postage_cost_inc']) : '';
     return $option;
 }
Ejemplo n.º 4
0
     $result = DBend($result);
     show_messages($result, $messageSuccess, $messageFailed);
 } elseif (isset($_REQUEST['add_service_time']) && isset($_REQUEST['new_service_time'])) {
     $_REQUEST['times'] = getRequest('times', array());
     $new_service_time['type'] = $_REQUEST['new_service_time']['type'];
     $result = true;
     if ($_REQUEST['new_service_time']['type'] == SERVICE_TIME_TYPE_ONETIME_DOWNTIME) {
         if (!validateDateTime($_REQUEST['new_service_time_from_year'], $_REQUEST['new_service_time_from_month'], $_REQUEST['new_service_time_from_day'], $_REQUEST['new_service_time_from_hour'], $_REQUEST['new_service_time_from_minute'])) {
             $result = false;
             error(_s('Invalid date "%s".', _('From')));
         }
         if (!validateDateInterval($_REQUEST['new_service_time_from_year'], $_REQUEST['new_service_time_from_month'], $_REQUEST['new_service_time_from_day'])) {
             $result = false;
             error(_s('"%s" must be between 1970.01.01 and 2038.01.18.', _('From')));
         }
         if (!validateDateTime($_REQUEST['new_service_time_to_year'], $_REQUEST['new_service_time_to_month'], $_REQUEST['new_service_time_to_day'], $_REQUEST['new_service_time_to_hour'], $_REQUEST['new_service_time_to_minute'])) {
             $result = false;
             error(_s('Invalid date "%s".', _('Till')));
         }
         if (!validateDateInterval($_REQUEST['new_service_time_to_year'], $_REQUEST['new_service_time_to_month'], $_REQUEST['new_service_time_to_day'])) {
             $result = false;
             error(_s('"%s" must be between 1970.01.01 and 2038.01.18.', _('Till')));
         }
         if ($result) {
             $new_service_time['ts_from'] = mktime($_REQUEST['new_service_time_from_hour'], $_REQUEST['new_service_time_from_minute'], 0, $_REQUEST['new_service_time_from_month'], $_REQUEST['new_service_time_from_day'], $_REQUEST['new_service_time_from_year']);
             $new_service_time['ts_to'] = mktime($_REQUEST['new_service_time_to_hour'], $_REQUEST['new_service_time_to_minute'], 0, $_REQUEST['new_service_time_to_month'], $_REQUEST['new_service_time_to_day'], $_REQUEST['new_service_time_to_year']);
             $new_service_time['note'] = $_REQUEST['new_service_time']['note'];
         }
     } else {
         $new_service_time['ts_from'] = dowHrMinToSec($_REQUEST['new_service_time']['from_week'], $_REQUEST['new_service_time']['from_hour'], $_REQUEST['new_service_time']['from_minute']);
         $new_service_time['ts_to'] = dowHrMinToSec($_REQUEST['new_service_time']['to_week'], $_REQUEST['new_service_time']['to_hour'], $_REQUEST['new_service_time']['to_minute']);
Ejemplo n.º 5
0
     }
     DBend($result);
 } elseif (isset($_REQUEST['add_service_time']) && isset($_REQUEST['new_service_time'])) {
     $_REQUEST['times'] = get_request('times', array());
     $new_service_time['type'] = $_REQUEST['new_service_time']['type'];
     $result = true;
     if ($_REQUEST['new_service_time']['type'] == SERVICE_TIME_TYPE_ONETIME_DOWNTIME) {
         if (!validateDateTime($_REQUEST['downtime_since_year'], $_REQUEST['downtime_since_month'], $_REQUEST['downtime_since_day'], $_REQUEST['downtime_since_hour'], $_REQUEST['downtime_since_minute'])) {
             $result = false;
             error(_s('Invalid date "%s".', _('From')));
         }
         if (!validateDateInterval($_REQUEST['downtime_since_year'], $_REQUEST['downtime_since_month'], $_REQUEST['downtime_since_day'])) {
             $result = false;
             error(_s('"%s" must be between 1970.01.01 and 2038.01.18.', _('From')));
         }
         if (!validateDateTime($_REQUEST['downtime_till_year'], $_REQUEST['downtime_till_month'], $_REQUEST['downtime_till_day'], $_REQUEST['downtime_till_hour'], $_REQUEST['downtime_till_minute'])) {
             $result = false;
             error(_s('Invalid date "%s".', _('Till')));
         }
         if (!validateDateInterval($_REQUEST['downtime_till_year'], $_REQUEST['downtime_till_month'], $_REQUEST['downtime_till_day'])) {
             $result = false;
             error(_s('"%s" must be between 1970.01.01 and 2038.01.18.', _('Till')));
         }
         if ($result) {
             $new_service_time['ts_from'] = mktime($_REQUEST['downtime_since_hour'], $_REQUEST['downtime_since_minute'], 0, $_REQUEST['downtime_since_month'], $_REQUEST['downtime_since_day'], $_REQUEST['downtime_since_year']);
             $new_service_time['ts_to'] = mktime($_REQUEST['downtime_till_hour'], $_REQUEST['downtime_till_minute'], 0, $_REQUEST['downtime_till_month'], $_REQUEST['downtime_till_day'], $_REQUEST['downtime_till_year']);
             $new_service_time['note'] = $_REQUEST['new_service_time']['note'];
         }
     } else {
         $new_service_time['ts_from'] = dowHrMinToSec($_REQUEST['new_service_time']['from_week'], $_REQUEST['new_service_time']['from_hour'], $_REQUEST['new_service_time']['from_minute']);
         $new_service_time['ts_to'] = dowHrMinToSec($_REQUEST['new_service_time']['to_week'], $_REQUEST['new_service_time']['to_hour'], $_REQUEST['new_service_time']['to_minute']);