Example #1
0
 function billSubmit()
 {
     global $configuration, $admin_id;
     $array_return = array();
     //kiểm tra xem có hóa đơn nào thực hiện ko, nếu có thì exit luôn
     $db_trigger = new db_query('SELECT tri_status FROM triggers WHERE tri_key = "billSubmit" LIMIT 1');
     $trigger = mysqli_fetch_assoc($db_trigger->result);
     unset($db_trigger);
     if ($trigger['tri_status'] == 1) {
         //đang có hóa đơn được thanh toán, exit luôn
         $array_return['error'] = 'Đang có hóa đơn khác được thanh toán, bạn vui lòng thử lại trong giây lát!';
         $this->add($array_return);
         return false;
     }
     //bắt đầu xử lý hàm submit hóa đơn
     $desk_id = getValue('desk_id', 'int', 'POST', 0);
     check_desk_exist($desk_id);
     if (!$desk_id) {
         $array_return['error'] = 'Bàn chưa được mở';
         $this->add($array_return);
         return false;
     }
     //kiểm tra xem bàn có thực đơn nào không?
     $db_count = new db_count('SELECT count(*) AS count FROM current_desk_menu WHERE cdm_desk_id = ' . $desk_id);
     if (!$db_count->total) {
         $array_return['error'] = 'Không thể thanh toán hóa đơn trống';
         $this->add($array_return);
         return false;
     }
     //Kiểm tra tồn kho
     $db_desk = new db_query('SELECT
                              *
                             FROM
                                 current_desk
                             LEFT JOIN current_desk_menu ON cud_desk_id = cdm_desk_id
                             WHERE cud_desk_id = ' . $desk_id);
     //mảng lưu list id thực đơn của bàn hiện tại
     $list_menu = array();
     //mảng lưu list số lượng tương ứng với từng thực đơn
     $list_quantity = array();
     //mảng lưu id của các thực đơn ko đủ số lượng tồn
     $disallow_menu = array();
     //mảng lưu thông tin về bàn
     $desk_detail = array();
     //mảng lưu thông tin về các thực đơn trong bàn
     $desk_menu_detail = array();
     while ($row = mysqli_fetch_assoc($db_desk->result)) {
         $desk_detail = $row;
         $desk_menu_detail[] = $row;
         $list_menu[] = $row['cdm_menu_id'];
         $list_quantity[$row['cdm_menu_id']] = $row['cdm_number'];
     }
     //lấy ra mảng số lượng tồn kho
     $allow_quantity = $this->calculateInventoryMenu($list_menu);
     //lặp qua mảng tồn kho để kiểm tra xem số lượng có đủ ko
     foreach ($allow_quantity as $men_id => $men_quantity) {
         if ($men_quantity < $list_quantity[$men_id]) {
             $disallow_menu[] = $men_id;
         }
     }
     //tinh tong tien can phai tra cua hoa don
     //mảng lưu tổng tiền của từng thực đơn trong bàn key=>value trong đó key : id thực đơn, value : tổng tiền thực đơn đó
     $array_money = array();
     //mảng lưu đơn giá của thực đơn
     $array_price = array();
     foreach ($desk_menu_detail as $cd_menu) {
         //select ra thong tin ve gia cua menu
         //neu menu duoc custom gia thi gia cua menu la gia cdm_price
         //neu menu khong duoc custom gia thi gia cua menu lay tu bang menu dua vao cdm_price_type
         $db_check = new db_query('SELECT men_editable, men_price, men_price1, men_price2
                                       FROM menus
                                       WHERE men_id = ' . $cd_menu['cdm_menu_id']);
         $cd_menu_detail = mysqli_fetch_assoc($db_check->result);
         unset($db_check);
         if ($cd_menu_detail['men_editable']) {
             //thực đơn cho phép chỉnh sửa giá : lấy giá của thực đơn trong cdm_price
             $array_money[$cd_menu['cdm_menu_id']] = $cd_menu['cdm_price'] * (1 - $cd_menu['cdm_menu_discount'] / 100) * $cd_menu['cdm_number'];
             $array_price[$cd_menu['cdm_menu_id']] = $cd_menu['cdm_price'];
         } else {
             //thực đơn không cho phép chỉnh sửa giá : lấy giá thực đơn theo cdm_price_type
             $array_money[$cd_menu['cdm_menu_id']] = $cd_menu_detail[$cd_menu['cdm_price_type']] * (1 - $cd_menu['cdm_menu_discount'] / 100) * $cd_menu['cdm_number'];
             $array_price[$cd_menu['cdm_menu_id']] = $cd_menu_detail[$cd_menu['cdm_price_type']];
         }
     }
     //kiểm tra ngày trả nợ - nếu nhỏ hơn ngày hiện tại thì đưa ra thông báo lỗi
     $debit = getValue('debit', 'int', 'POST', 0);
     $date_debit = getValue('date', 'str', 'POST', '');
     $date_debit = convertDateTime($date_debit, '0:0:0');
     if ($debit) {
         //có ghi nợ - kiểm tra ngày trả nợ
         if ($date_debit < time()) {
             $array_return['error'] = 'Ngày hẹn trả không phù hợp';
             $this->add($array_return);
             return false;
         }
     }
     //Kiểm tra xem có cho phép xuất âm kho hàng không
     //Hiện tại trong config không cho phép xuất âm - làm dần dần
     if (count($disallow_menu) > 0 && !$configuration['con_negative_export']) {
         //thực đơn không đủ số lượng tồn kho, đưa ra thông báo lỗi
         $array_return['error'] = 'Không thể xuất do không đủ số lượng tồn kho';
         $array_return['disallow_menu'] = json_encode($disallow_menu);
         $this->add($array_return);
         return false;
     } else {
         //Không có hóa đơn nào đang được xử lý - cập nhật trigger status thành 1 để bắt đầu vào hàm
         $db_update = new db_execute('UPDATE triggers SET tri_status = 1 WHERE tri_key = "billSubmit" LIMIT 1');
         unset($db_update);
         //bắt đầu tạo và thanh toán hóa đơn
         //trừ số lượng sản phẩm trong hóa đơn vào kho hàng
         foreach ($list_menu as $men_id) {
             //lấy ra các sản phẩm có trong thực đơn, sau đó trừ đi
             $db_product = new db_query('SELECT *
                                         FROM menu_products
                                         LEFT JOIN product_quantity ON product_id = mep_product_id
                                         WHERE mep_menu_id = ' . $men_id . '
                                         AND store_id = ' . $configuration['con_default_store']);
             while ($row_pro = mysqli_fetch_assoc($db_product->result)) {
                 $sql_minus = 'UPDATE product_quantity
                               SET pro_quantity = pro_quantity - ' . $row_pro['mep_quantity'] * $list_quantity[$row_pro['mep_menu_id']] . '
                               WHERE product_id = ' . $row_pro['product_id'] . ' AND store_id = ' . $configuration['con_default_store'];
                 $db_update = new db_execute($sql_minus);
                 unset($db_update);
             }
         }
         //sau khi trừ xong sản phẩm thì insert vào bảng thu chi và bảng hóa đơn
         //insert vào bảng hóa đơn bán hàng bill_in
         //giờ vào bàn
         $bii_start_time = $desk_detail['cud_start_time'];
         //giờ đóng bàn
         $bii_end_time = time();
         //id của bàn
         $bii_desk_id = $desk_id;
         //id kho xuất hàng
         $bii_store_id = $configuration['con_default_store'];
         //id quầy phục vụ
         $bii_service_desk_id = $configuration['con_default_svdesk'];
         //id khách hàng
         $bii_customer_id = $desk_detail['cud_customer_id'];
         //id nhân viên bán hàng
         $bii_staff_id = $desk_detail['cud_staff_id'];
         //id thu ngân - người lập hóa đơn
         $bii_admin_id = $admin_id;
         //loại thanh toán - tiền mặt hay thẻ.
         $bii_type = getValue('payType', 'int', 'POST', PAY_TYPE_CASH);
         $bii_type = $bii_type == PAY_TYPE_CASH ? PAY_TYPE_CASH : PAY_TYPE_CARD;
         //phụ phí
         $bii_extra_fee = $desk_detail['cud_extra_fee'];
         //thue VAT
         $bii_vat = $desk_detail['cud_vat'];
         //giam gia
         $bii_discount = $desk_detail['cud_customer_discount'];
         //tong tien
         $bii_true_money = 0;
         foreach ($array_money as $key => $money) {
             $bii_true_money += $money;
         }
         //tính giảm giá, thuế và phụ phí để ra số tiền thực tế
         $bii_true_money = $bii_true_money * (100 - $bii_discount + $bii_extra_fee) / 100 * (100 + $bii_vat) / 100;
         //tiền làm tròn
         $bii_round_money = round($bii_true_money, -3);
         if ($debit && $debit < $bii_true_money) {
             $bii_status = BILL_STATUS_DEBIT;
             $bii_money_debit = $bii_true_money - $debit;
             $bii_date_debit = $date_debit;
         } else {
             $bii_status = BILL_STATUS_SUCCESS;
             $bii_money_debit = 0;
             $bii_date_debit = 0;
         }
         //insert vào bảng bill_in
         $sql_insert = 'INSERT INTO bill_in (
                             bii_start_time,
                             bii_end_time,
                             bii_desk_id,
                             bii_store_id,
                             bii_customer_id,
                             bii_staff_id,
                             bii_admin_id,
                             bii_status,
                             bii_type,
                             bii_extra_fee,
                             bii_vat,
                             bii_discount,
                             bii_true_money,
                             bii_round_money,
                             bii_service_desk_id,
                             bii_money_debit,
                             bii_date_debit
                         )
                         VALUES (
                         ' . $bii_start_time . ',
                         ' . $bii_end_time . ',
                         ' . $bii_desk_id . ',
                         ' . $bii_store_id . ',
                         ' . $bii_customer_id . ',
                         ' . $bii_staff_id . ',
                         ' . $bii_admin_id . ',
                         ' . $bii_status . ',
                         ' . $bii_type . ',
                         ' . $bii_extra_fee . ',
                         ' . $bii_vat . ',
                         ' . $bii_discount . ',
                         ' . $bii_true_money . ',
                         ' . $bii_round_money . ',
                         ' . $bii_service_desk_id . ',
                         ' . $bii_money_debit . ',
                         ' . $bii_date_debit . '
                         )';
         $db_insert = new db_execute_return();
         $bill_success_id = $db_insert->db_execute($sql_insert);
         //insert chi tiết hóa đơn vào bảng bill_in_detail
         $sql_insert = 'INSERT INTO bill_in_detail (
                           bid_bill_id,
                           bid_menu_id,
                           bid_menu_discount,
                           bid_menu_number,
                           bid_menu_price
                        ) VALUES ';
         foreach ($desk_menu_detail as $cd_menu) {
             $sql_insert .= '(
             ' . $bill_success_id . ',
             ' . $cd_menu['cdm_menu_id'] . ',
             ' . $cd_menu['cdm_menu_discount'] . ',
             ' . $cd_menu['cdm_number'] . ',
             ' . $array_price[$cd_menu['cdm_menu_id']] . '),';
         }
         $sql_insert = rtrim($sql_insert, ',');
         $db_insert = new db_execute($sql_insert);
         unset($db_insert);
         //phát sinh 1 phiếu thu - insert dữ liệu vào phiếu thu
         //logic : hóa đơn ghi nợ thì phát sinh phiếu thu với 1 phần số tiền đã thu. hóa đơn trả đủ thì insert bình thường
         $fin_money = $bii_true_money;
         if ($debit) {
             $fin_money = $bii_true_money - $bii_money_debit;
         }
         //làm tròn số
         $fin_money = round($fin_money);
         //lấy thông tin khách hàng
         if ($bii_customer_id) {
             $db_customer = new db_query('SELECT * FROM customers WHERE cus_id = ' . $bii_customer_id . ' LIMIT 1');
             $customer = mysqli_fetch_assoc($db_customer->result);
             $fin_username = $customer['cus_name'];
             $fin_address = $customer['cus_address'];
         } else {
             $fin_username = '******';
             $fin_address = '';
         }
         $sql_insert = 'INSERT INTO financial
                         (fin_date, fin_updated_time, fin_money, fin_reason_other,
                         fin_billcode, fin_username, fin_address, fin_cat_id,
                         fin_pay_type, fin_note, fin_admin_id, fin_agency_id)
                         VALUES
                         (
                         ' . $bii_end_time . ',
                         ' . $bii_end_time . ',
                         ' . $fin_money . ',
                         "Bán hàng",
                         "' . $bill_success_id . '",
                         "' . $fin_username . '",
                         "' . $fin_address . '",
                         ' . FINANCIAL_CAT_BAN_HANG . ',
                         ' . $bii_type . ',
                         "",
                         ' . $admin_id . ',
                         ' . $configuration['con_default_agency'] . '
                         )';
         $db_insert = new db_execute($sql_insert);
         if ($db_insert->total) {
             //thanh toán xong thì xóa bàn
             $db_delete_desk = new db_execute('DELETE FROM current_desk WHERE cud_desk_id = ' . $desk_id);
             $db_delete_desk = new db_execute('DELETE FROM current_desk_menu WHERE cdm_desk_id = ' . $desk_id);
             unset($db_insert, $db_delete_desk);
             //return lại mã hóa đơn
             $array_return['success'] = 1;
             $array_return['bii_id'] = $bill_success_id;
         } else {
             $array_return['error'] = 'Lỗi không rõ lý do';
         }
     }
     //thực hiện update trigger về 0 để giải phóng function
     $db_update = new db_execute('UPDATE triggers SET tri_status = 0 WHERE tri_key = "billSubmit" LIMIT 1');
     unset($db_update);
     //trả kết quả về client
     $this->add($array_return);
 }
Example #2
0
if ($isAjaxRequest && isset($_POST['id_brand'])) {
    $id_brand = getValue('id_brand', 'int', 'POST', 0);
    $time_start = convertDateTime(getValue('time_start', 'str', 'POST', ''), '0:0:0');
    $time_end = convertDateTime(getValue('time_end', 'str', 'POST', ''), '23:59:59');
    if ($id_brand) {
        $and_bio_sup_id .= ' AND bio_supplier_id = ' . intval($id_brand);
    }
    // loc theo id nha cung cap
    if ($time_start) {
        $and_bio_sup_id .= $type_bill_fillter . ' >= ' . $time_start;
    }
    if ($time_end) {
        $and_bio_sup_id .= $type_bill_fillter . ' <= ' . $time_end;
    }
} else {
    $and_bio_sup_id = $type_bill_fillter . ' >= ' . (convertDateTime($today, '0:0:0') - 2592000) . $type_bill_fillter . ' <= ' . convertDateTime($today, '23:59:59');
}
$db_count = new db_count('SELECT count(*) as count
                            FROM ' . $bg_table_o . '
                            WHERE 1 ' . $list_right->sqlSearch() . $and_bio_sup_id . '
                            ');
$total_ = $db_count->total;
unset($db_count);
$db_listing = new db_query('SELECT *
                            FROM ' . $bg_table_o . '
                            WHERE 1 ' . $list_right->sqlSearch() . $and_bio_sup_id . '
                            ORDER BY ' . $list_right->sqlSort() . ' ' . $id_field_o . ' ASC
                            ' . $list_right->limit($total_));
$total_row = mysqli_num_rows($db_listing->result);
$right_column .= '<div id="table_bill_out">';
$table_right_column = '';
/* Tổng tiền trước khi giảm*/
$array_data = array();
/* Mảng dữ liệu cần lấy*/
$array_day = array();
/* Dữ liệu thời gian*/
$array_date = array();
while ($row = mysqli_fetch_assoc($db_listing->result)) {
    /* Tạo mảng dữ liệu để hiển thị biểu đồ JS*/
    $start_day = gmdate('d/m/Y', $row['log_time_in']);
    $array_day[$start_day] = $row;
    /* Lấy mảng dữ liệu*/
    $db_query_admin = new db_query('SELECT * FROM logs_session');
    $row_log = mysqli_fetch_assoc($db_query_admin->result);
    unset($db_query_admin);
    /* Thời gian admin log sẽ chỉ tính trong ngày hôm đó*/
    $start_day = convertDateTime(date('d/m/Y', $row['log_time_in']), '0:0:0');
    $end_day = $start_day + 86400 - 1;
    /* Tổng thu tổng chi của admin được lấy từ bill_in bảng hóa đơn bán hàng */
    $total_money_real = 0;
    $money_real_in = 0;
    /* Tiền mặt thu*/
    $money_cash_in = 0;
    /* Tiền thẻ thu*/
    $db_bill = new db_query('SELECT * FROM bill_in
                             WHERE bii_admin_id = ' . $row['log_admin_id'] . '
                             AND bii_start_time >= ' . $start_day . '
                             AND bii_start_time <= ' . $end_day . '
                               ');
    while ($row_bill_money = mysqli_fetch_assoc($db_bill->result)) {
        /* Hiển thị số tiền nếu hóa đơn ghi nợ*/
        $db_fina = new db_query('SELECT fin_money,fin_pay_type FROM financial WHERE fin_billcode = ' . $row_bill_money['bii_id'] . '');
Example #4
0
\t\t\t\t<th>Grade
\t\t\t\t<th>Referrals
\t\t\t\t<th>Joined
\t\t\t\t<th>Last online
\t\t\t</tr>
\t\t</thead>
\t\t<tbody>
EOF;
$i = 0;
foreach ($users->find()->sort(array("last" => -1)) as $k => $v) {
    $i++;
    $v['travels'] = getCount(getTravels(array("user" => $v['facebookid'])));
    $v['requests'] = getCount(getRequests(array("user" => $v['facebookid'])));
    $v['grade'] = 4.6;
    $v['referrals'] = 26;
    $v['joined'] = @convertDateTime($v['date'], false);
    $v['online'] = relativeTime($v['last']);
    $HTML[] = @<<<EOF
\t\t<tr>
\t\t\t<td>{$i}
\t\t\t<td><a href="?users/view/{$v['facebookid']}">{$v['first']}</a> 
\t\t\t<td>{$v['travels']}
\t\t\t<td>{$v['requests']}
\t\t\t<td>{$v['grade']}
\t\t\t<td>{$v['referrals']}
\t\t\t<td>{$v['joined']}
\t\t\t<td>{$v['online']}
\t\t</tr>
EOF;
}
$HTML[] = <<<EOF
Example #5
0
        $HTML[] = <<<EOF

\t<div class="front-search front-search-extra">
\tor submit request for your product<br><br>
\t<a href="?product_request/add" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span> SUBMIT NEW PRODUCT REQUEST</a>
\t</div>\t
EOF;
    }
} else {
    foreach ($results_travelers as $k => $v) {
        $user = @getUser($v['user']);
        $user['first'] = generateUserLink($v['user']);
        $pic = getUserPicture($user['facebookid']);
        $v['from'] = "<a href='https://maps.google.com/?q={$v['from']}' target='_blank'>" . strtoupper($v['from']) . "</a>";
        $v['to'] = "<a href='https://maps.google.com/?q={$v['to']}' target='_blank'>" . strtoupper($v['to']) . "</a>";
        $v['date'] = convertDateTime($v['date'], false) . " - " . dateToRelative($v['date'], false);
        $tmp3 = empty($v['size']) ? "" : "";
        $tmp4 = empty($v['weight']) ? "" : "";
        // luggage type: <span class="glyphicon glyphicon-briefcase"></span>
        // info: <span class="glyphicon glyphicon-info-sign"></span>
        $tmp5 = "Created " . relativeTime($v['update']);
        $HTML[] = <<<EOF
\t<div class="search-element">
\t\t<div class="search-profile">
\t\t\t<img src="{$pic}">
\t\t</div>
\t\t<div class="search-description">
\t\t\t{$v['description']}
\t\t</div>
\t\t<div class="search-details">
\t\t\t<span class="glyphicon glyphicon-user"></span> {$user['first']}
Example #6
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;
 }
Example #7
0
 $_SESSION["user_id"] = $user_id;
 $_SESSION['user_group_id'] = $row['adm_group_id'];
 $_SESSION["userlogin"] = $username;
 $_SESSION["username"] = $row['adm_name'];
 $_SESSION["user_note"] = $row['adm_note'];
 $_SESSION["password"] = md5($password);
 $_SESSION["isAdmin"] = $isAdmin;
 $_SESSION['isSuperAdmin'] = $isSuperAdmin;
 unset($db_isadmin);
 $db_query_log = new db_query('SELECT * FROM logs_session WHERE log_admin_id =' . $user_id . '
                              ORDER BY log_time_in DESC LIMIT 1');
 $row_log = mysqli_fetch_assoc($db_query_log->result);
 unset($db_query_log);
 $time_log_start = convertDateTime(date('d/m/Y', $row_log['log_time_in']), '0:0:0');
 // reset thời gian về đầu ngày
 $time_log = convertDateTime(date('d/m/Y', time()), '0:0:0');
 if ($time_log != $time_log_start) {
     /* Khi đăng nhập thì lưu lại log admin đăng nhập vào khoảng thời gian nào*/
     $db_admin_log = 'INSERT INTO logs_session (log_admin_id,log_time_in) VALUES (' . $user_id . ',' . time() . ')';
     $db_exc_logs = new db_execute($db_admin_log);
     unset($db_exc_logs);
 }
 if (!$isAdmin && !$isSuperAdmin) {
     $_SESSION['user_config'] = $row['adm_user_config'];
     redirect('index.php');
 } else {
     //kiểm tra xem acc đã được config chưa
     $db_check = new db_query('SELECT * FROM configurations WHERE con_admin_id = ' . $user_id);
     if (mysqli_num_rows($db_check->result) < 1) {
         //chưa có config thì redirect đến file config
         redirect('user_config.php');
Example #8
0
$name = '';
$date = '';
$debit = '';
$name_obj = '';
$date_type = '';
$And = '';
$obj = '';
if ($isAjaxRequest) {
    if (!isset($_GET['time_start']) || !isset($_GET['time_end'])) {
        die;
    }
    $t_start = getValue('time_start', 'str');
    $t_start = convertDateTime($t_start, '0:0:0');
    $t_end = getValue('time_end', 'str');
    $t_end = convertDateTime($t_end, '0:0:0') + 86400;
    $today = convertDateTime(time(), '0:0:0');
    //
    if ($t_start != $today && $type == 'customer') {
        $And = 'AND bii_end_time >= ' . $t_start;
    }
    if ($t_end != $today + 86400 && $type == 'customer') {
        $And = 'AND bii_end_time <= ' . $t_end;
    }
    if ($t_start != $today && $t_end != $today + 86400 && $type == 'customer') {
        $And = 'AND bii_end_time <= ' . $t_end . ' AND bii_end_time >= ' . $t_start;
    }
    if ($t_start == $today && $t_end == $today + 86400 && $type == 'customer') {
        $And = '';
    }
    //
    if ($t_start != $today && $type == 'supplier') {
Example #9
0
    $sql_phieuthu = ' AND cat_type IN("money_in")';
}
if ($check_system_out) {
    $sql_phieuchi = ' AND cat_type IN("money_out","money_system_out")';
} else {
    $sql_phieuchi = ' AND cat_type IN("money_out")';
}
//hiển thị các phiếu thu chi theo thời gian
$start_date_in = getValue('start_date_in', 'str', 'POST', '');
$start_date_in = $start_date_in ? convertDateTime($start_date_in, '0:0:0') : $default_start_date_in;
$end_date_in = getValue('end_date_in', 'str', 'POST', '');
$end_date_in = $end_date_in ? convertDateTime($end_date_in, '23:59:59') : $default_end_date_in;
$start_date_out = getValue('start_date_out', 'str', 'POST', '');
$start_date_out = $start_date_out ? convertDateTime($start_date_out, '0:0:0') : $default_start_date_out;
$end_date_out = getValue('end_date_out', 'str', 'POST', '');
$end_date_out = $end_date_out ? convertDateTime($end_date_out, '23:59:59') : $default_end_date_out;
$sql_date_in = '';
$sql_date_in .= ' AND fin_date >= ' . $start_date_in . ' AND fin_date <= ' . $end_date_in;
$sql_date_out = '';
$sql_date_out .= ' AND fin_date >= ' . $start_date_out . ' AND fin_date <= ' . $end_date_out;
$db_count = new db_count('SELECT count(*) as count
                            FROM ' . $bg_table . '
                            LEFT JOIN categories_multi ON cat_id = fin_cat_id
                            WHERE 1 ' . $list->sqlSearch() . $sql_phieuthu . $sql_date_in . '
                            ');
$total = $db_count->total;
unset($db_count);
$db_listing = new db_query('SELECT *
                            FROM ' . $bg_table . '
                            LEFT JOIN categories_multi ON cat_id = fin_cat_id
                            WHERE 1 ' . $list->sqlSearch() . $sql_phieuthu . $sql_date_in . '
Example #10
0
#+
#+ Khai bao bien
$add				= "add.php";
$listing			= "listing.php";
$edit				= "edit.php";
$after_save_data	= getValue("after_save_data", "str", "POST", $listing);

$errorMsg 			= "";		//Warning Error!
$action				= getValue("action", "str", "POST", "");
$fs_action			= getURL();
$record_id			= getValue("record_id");

$seo_strdate		= getValue("seo_strdate", "str", "POST", date("d/m/Y"));
$seo_strtime		= getValue("seo_strtime", "str", "POST", date("H:i:s"));
$seo_date			= convertDateTime($seo_strdate, $seo_strtime);

#+
#+ Goi class generate form
$myform = new generate_form();	//Call Class generate_form();
$myform->removeHTML(0);	//Loại bỏ chức năng không cho điền tag html trong form
#+
#+ Khai bao bang du lieu
$myform->addTable($fs_table);	// Add table
#+
#+ Khai bao thong tin cac truong
$myform->add("seo_link","seo_link",0,0,"",0,tt("Điền link SEO"),0,"");
$myform->add("seo_title","seo_title",0,0,"",0,tt("Điền title SEO"),0,"");
$myform->add("seo_description","seo_description",0,0,"",0,tt("Điền description SEO"),0,"");
$myform->add("seo_keyword","seo_keyword",0,0,"",0,tt("Điền keyword SEO"),0,"");
/*/
Example #11
0
 function fillerStockTransfer()
 {
     $right_column = '';
     //Hiển thị danh sách phiếu thu bên trái
     #Bắt đầu với datagird
     $list = new dataGrid('sto_id', 30);
     $list->add('', 'Số phiếu');
     $list->add('', 'Nhân viên chuyển');
     $list->add('', 'Ngày chuyển');
     $list->add('', 'Từ kho');
     $list->add('', 'Đến kho');
     // lấy biên từ form tìm kiếm theo ngày và nhân viên
     $start_date_in = getValue('start_date_in', 'str', 'POST', 0);
     $date_from = convertDateTime($start_date_in, '0:0:0');
     $end_date_in = getValue('end_date_in', 'str', 'POST', 0);
     $date_to = convertDateTime($end_date_in, '0:0:0');
     $staff_id = getValue('list_staff_id', 'int', 'POST', 0);
     if ($start_date_in && $end_date_in && $staff_id) {
         $search_sql = ' AND sto_time >=' . $date_from . ' AND sto_time <=' . $date_to . ' AND sto_staff_id = ' . $staff_id . ' ';
     } elseif ($staff_id) {
         $search_sql = ' AND sto_staff_id = ' . $staff_id . '';
     } elseif ($start_date_in && $end_date_in) {
         $search_sql = ' AND sto_time >=' . $date_from . ' AND sto_time <=' . $date_to . '';
     } else {
         $search_sql = '';
     }
     // slect list danh sách phiếu kiểm kê
     $db_count = new db_count('SELECT count(*) as count
                         FROM stock_transfer
                         WHERE 1 ' . $list->sqlSearch() . $search_sql . '
                         ');
     $total = $db_count->total;
     unset($db_count);
     $sql_query = 'SELECT *
                         FROM stock_transfer
                         WHERE 1 ' . $list->sqlSearch() . $search_sql . '
                         ORDER BY ' . $list->sqlSort() . ' sto_id DESC
                         ' . $list->limit($total);
     $db_listing = new db_query($sql_query);
     $total_row = mysqli_num_rows($db_listing->result);
     // tạo mảng để hiện thị tên nhân viên
     $staff_array = array();
     $db_staff = new db_query('SELECT * FROM users');
     while ($row_user = mysqli_fetch_assoc($db_staff->result)) {
         $staff_array[$row_user['use_id']] = $row_user['use_name'];
     }
     // tạo mảng để hiện thị kho hàng
     $store_array = array();
     $db_store = new db_query('SELECT * FROM categories_multi WHERE cat_type = "stores" ');
     while ($row_store = mysqli_fetch_assoc($db_store->result)) {
         $store_array[$row_store['cat_id']] = $row_store['cat_name'];
     }
     //Vì đây là module cần 2 table listing nên khai báo thêm table_extra id=table-listing-left
     $right_column .= $list->showHeader($total_row, '', 'id="table-listing-right"');
     $i = 0;
     while ($row = mysqli_fetch_assoc($db_listing->result)) {
         $i++;
         $right_column .= $list->start_tr($i, $row['sto_id'], 'class="menu-normal record-item" ondblclick="detail_stock_transfer(' . $row['sto_id'] . ')" dblclick="detail_record(' . $row['sto_id'] . ')" onclick="active_record(' . $row['sto_id'] . ')" data-record_id="' . $row['sto_id'] . '"');
         /* code something */
         //Số phiếu - ID phiếu
         $right_column .= '<td class="center" width="">' . format_codenumber($row['sto_id'], 6) . '</td>';
         //Người trả
         $right_column .= '<td width="120" class="center">' . $staff_array[$row['sto_staff_id']] . '</td>';
         //Mô tả
         $right_column .= '<td class="center">' . date('d/m/Y H:i', $row['sto_time']) . '</td>';
         //số tiền
         $right_column .= '<td width="120" class="text-left">' . $store_array[$row['sto_from_storeid']] . '</td>';
         $right_column .= '<td width="120" class="text-left">' . $store_array[$row['sto_to_storeid']] . '</td>';
         $right_column .= $list->end_tr();
     }
     $right_column .= $list->showFooter();
     $this->add($right_column);
 }
Example #12
0
 function reportProducts()
 {
     $array_return = array();
     //lấy các giá trị bắn ajax về để xuất báo cáo
     $array_product = getValue('products', 'arr', 'POST', '');
     if (!$array_product) {
         $array_return['content'] = 'Chưa chọn sản phẩm';
         die(json_encode($array_return));
     }
     $store_id = getValue('store_id', 'int', 'POST', 0);
     if (!$store_id) {
         $array_return['content'] = 'Chưa chọn kho hàng';
         die(json_encode($array_return));
     }
     $start_date = convertDateTime(getValue('start_date', 'str', 'POST', ''), '0:0:0');
     $end_date = convertDateTime(getValue('end_date', 'str', 'POST', ''), '0:0:0');
     // select ra báo cáo với các thông tin trên
     //lấy số lượng nhập hàng
     $arr_pro = array();
     foreach ($array_product as $product) {
         $arr_pro[] = $product;
     }
     $arr_pro = implode(',', $arr_pro);
     $left_column = '';
     //Hiển thị danh sách phiếu thu bên trái
     #Bắt đầu với datagird
     $list = new dataGrid('pro_id', 100);
     $list->add('', 'Tên mặt hàng');
     $list->add('', 'ĐVT');
     $list->add('', 'SL nhập');
     $list->add('', 'Tổng tiền tồn');
     // tảo mảng bill_id lọc theo thời gian và theo kho hàng
     $array_bill = array();
     $db_bill_out = new db_query('SELECT bio_id FROM bill_out WHERE bio_start_time >= ' . $start_date . '
                                  AND bio_start_time <=' . $end_date . ' AND bio_store_id = ' . $store_id . '');
     while ($row_bill_out = mysqli_fetch_assoc($db_bill_out->result)) {
         $array_bill[] = $row_bill_out['bio_id'];
     }
     unset($db_bill_out);
     $array_bill = implode(',', $array_bill);
     if ($array_bill == null) {
         $sql_search = ' AND bid_bill_id IN(0)';
     } else {
         $sql_search = ' AND bid_pro_id IN(' . $arr_pro . ') AND bid_bill_id IN(' . $array_bill . ')';
     }
     // select list danh
     $db_count = new db_count('SELECT count(*) as count
                         FROM bill_out_detail
                         WHERE 1 ' . $list->sqlSearch() . $sql_search . '
                         GROUP BY bid_pro_id
                         ');
     $total = $db_count->total;
     unset($db_count);
     $sql_query = 'SELECT * FROM bill_out_detail
                         WHERE 1 ' . $list->sqlSearch() . $sql_search . '
                         GROUP BY bid_pro_id
                         ORDER BY ' . $list->sqlSort() . ' bid_pro_id ASC
                         ' . $list->limit($total);
     $db_listing = new db_query($sql_query);
     $total_row = mysqli_num_rows($db_listing->result);
     //tao mang hien thi ten product
     $array_pro_name = array();
     $db_product = new db_query('SELECT pro_id,pro_name FROM products');
     while ($row_pro = mysqli_fetch_assoc($db_product->result)) {
         $array_pro_name[$row_pro['pro_id']] = $row_pro['pro_name'];
     }
     //Vì đây là module cần 2 table listing nên khai báo thêm table_extra id=table-listing-left
     $left_column .= $list->showHeader($total_row, '', 'id="table-listing-right"');
     $i = 0;
     $total_all = 0;
     while ($row = mysqli_fetch_assoc($db_listing->result)) {
         $i++;
         // lấy ra pro_unit_id để
         $db_query_unit = new db_query('SELECT pro_unit_id FROM products WHERE pro_id = ' . $row['bid_pro_id'] . ' ');
         $row_pro_unit = mysqli_fetch_assoc($db_query_unit->result);
         // lấy ra đơn vị tính của sản phẩm
         $db_unit_name = new db_query('SELECT uni_name FROM units WHERE uni_id = ' . $row_pro_unit['pro_unit_id'] . '');
         $row_unit = mysqli_fetch_assoc($db_unit_name->result);
         //tính tổng số lượng và giá tiền theo mặt hàng
         $db_price_ave = new db_query('SELECT SUM(bid_pro_price) AS total_price,
                                         SUM(bid_pro_number) AS total_number
                                         FROM bill_out_detail
                                         WHERE bid_pro_id = ' . $row['bid_pro_id'] . '');
         $row_total = mysqli_fetch_assoc($db_price_ave->result);
         $left_column .= $list->start_tr($i, $row['bid_pro_id'], 'class="menu-normal record-item" data-record_id="' . $row['bid_pro_id'] . '"');
         /* code something */
         $left_column .= '<td class="text-left">' . $array_pro_name[$row['bid_pro_id']] . '</td>';
         $left_column .= '<td width="100" class="center">' . $row_unit['uni_name'] . '</td>';
         $left_column .= '<td width="120" class="text-right">' . $row_total['total_number'] . '</td>';
         $left_column .= '<td width="120"  class="text-right">' . number_format($row_total['total_price']) . '</td>';
         // tổng tiền tất cả mặt hàng đã chọn
         $total_all += $row_total['total_number'] * $row_total['total_price'];
         $left_column .= $list->end_tr();
     }
     unset($db_count_price);
     unset($db_price_ave);
     unset($db_listing);
     unset($db_unit_name);
     unset($db_query_unit);
     $left_column .= $list->showFooter();
     $array_return['content'] = $left_column;
     $array_return['total'] = number_format($total_all);
     die(json_encode($array_return));
 }
Example #13
0
<?php

$HTML[] = <<<EOF
\t<h1>User feedback</h1>
EOF;
$feedback = $db->feedback;
foreach ($feedback->find()->sort(array("date" => -1)) as $k => $v) {
    $pic = generateUserPicture($v['user'], "chat-picture");
    $time = relativeTime($v['update']);
    $date = convertDateTime($v['date'], true);
    $HTML[] = <<<EOF
\t<div class="request-chat">
\t\t{$pic}
\t\t{$v['feedback']}<br>
\t\t<small>{$time} &middot; {$date}</small>
\t</div>
EOF;
}
Example #14
0
            <span class="control-btn control-btn-refresh"><i class="fa fa-refresh"></i> Làm mới</span>
            <span class="control-btn control-btn-recover" onclick="list_trash_stock_trans()"><i class="fa fa-recycle"></i> Thùng rác (' . $trash_count_stock . ')</span>
        </div>';
//Hiển thị danh sách phiếu thu bên trái
#Bắt đầu với datagird
$list = new dataGrid('sto_id', 30);
$list->add('', 'Số phiếu');
$list->add('', 'Nhân viên chuyển');
$list->add('', 'Ngày chuyển');
$list->add('', 'Từ kho');
$list->add('', 'Đến kho');
// lấy biên từ form tìm kiếm theo ngày và nhân viên
$start_date_in = getValue('start_date_in', 'str', 'POST', 0);
$date_from = convertDateTime('d/m/Y', $start_date_in);
$end_date_in = getValue('end_date_in', 'str', 'POST', 0);
$date_to = convertDateTime('d/m/Y', $end_date_in);
$staff_name = getValue('list_staff_id', 'int', 'POST', 0);
// slect list danh sách phiếu kiểm kê
$db_count = new db_count('SELECT count(*) as count
                            FROM stock_transfer
                            WHERE 1 ' . $list->sqlSearch() . '
                            ');
$total = $db_count->total;
unset($db_count);
$db_listing = new db_query('SELECT *
                            FROM stock_transfer
                            WHERE 1 ' . $list->sqlSearch() . '
                            ORDER BY ' . $list->sqlSort() . ' sto_id DESC
                            ' . $list->limit($total));
$total_row = mysqli_num_rows($db_listing->result);
// tạo mảng để hiện thị tên nhân viên
Example #15
0
#+
#+ Khai bao bien
$add				= "add.php";
$listing			= "listing.php";
$edit				= "edit.php";
$after_save_data	= getValue("after_save_data", "str", "POST", $listing);

$errorMsg 			= "";		//Warning Error!
$action				= getValue("action", "str", "POST", "");
$fs_action			= getURL();
$record_id			= getValue("record_id");

$sta_strdate		= getValue("sta_strdate", "str", "POST", date("d/m/Y"));
$sta_strtime		= getValue("sta_strtime", "str", "POST", date("H:i:s"));
$sta_date			= convertDateTime($sta_strdate, $sta_strtime);

#+
checkRowUser($fs_table,$field_id,$record_id,$listing);

#+
#+ Goi class generate form
$myform = new generate_form();	//Call Class generate_form();
$myform->removeHTML(0);	//Loại bỏ chức năng không cho điền tag html trong form
#+
#+ Khai bao bang du lieu
$myform->addTable($fs_table);	// Add table
#+
#+ Khai bao thong tin cac truong
$myform->add("sta_category_id", "sta_category_id", 1, 0, 0, 1, "Bạn chưa chọn danh mục.", 0, "");
$myform->add("sta_title", "sta_title", 0, 0, "", 1, "Bạn chưa nhập tiêu đề.", 0, "");
Example #16
0
    foreach ($compare_dates as $same_day) {
        if (gmdate("d/m/Y", $same_day['date']) == $date) {
            $soHD += 1;
            $chiphi += $same_day['money'];
            $fin_id[] = $same_day['id_fin'];
            $pay_Cash += $same_day['cash'];
            $pay_Card += $same_day['card'];
        }
    }
    if (count($fin_id) > 1) {
        $fin_id = implode('_', $fin_id);
    } else {
        $fin_id = implode('', $fin_id);
    }
    //
    $array_date['x'] = convertDateTime($date, '0:0:0');
    $array_date['y'] = intval($chiphi);
    $array[] = $array_date;
    //
    $right_column .= $list->start_tr($i, $fin_id, 'class="menu-normal record-item"');
    $right_column .= '<td class="center"> Trong ngày: ' . $date . '</td>';
    $right_column .= '<td class="center">' . $soHD . '</td>';
    $right_column .= '<td class="text-right">' . number_format($chiphi) . '</td>';
    $right_column .= '<td class="text-right">' . number_format($pay_Cash) . '</td>';
    $right_column .= '<td class="text-right">' . number_format($pay_Card) . '</td>';
    $right_column .= $list->end_tr();
}
$right_column .= $list->showFooter();
$right_column .= '<div id="chartContainer"></div>';
$title['title'] = "Chi phí theo quỹ tiền";
// total report
$list->add('', 'Cộng trước giảm');
$list->add('', 'Giảm');
$list->add('', 'Phí DV');
$list->add('', 'VAT');
$list->add('', 'Tổng tiền');
$list->add('', 'Tiền mặt');
$list->add('', 'Thẻ');
$list->add('', 'Ghi nợ');
/* Lấy các thông tin bắn ajax về*/
$start_date = convertDateTime(getValue('start_date', 'str', 'POST', ''), '0:0:0');
$end_date = convertDateTime(getValue('end_date', 'str', 'POST', ''), '0:0:0') + 86400 - 1;
$store_id = getValue('store_id', 'int', 'POST', 0);
$admin_id = getValue('admin_id', 'int', 'POST', 0);
$start_today = convertDateTime(time(), '0:0:0');
// bắt đầu trong ngày từ 00
$end_today = convertDateTime(time(), '0:0:0') + 86400 - 1;
// kết thúc ngày
if ($isAjaxRequest) {
    if ($start_date) {
        $sql_search .= ' AND bii_start_time >= ' . $start_date;
    }
    if ($end_date) {
        $sql_search .= ' AND bii_start_time <= ' . $end_date;
    }
    if ($store_id != 0) {
        $sql_search .= ' AND bii_store_id = ' . $store_id;
    }
    if ($admin_id != 0) {
        $sql_search .= ' AND bii_admin_id = ' . $admin_id;
    }
} else {
Example #18
0
 function EditRecord()
 {
     //check quyền
     checkCustomPermission('edit');
     //khai bao bien global
     global $time_end, $time_start;
     $promo_id = getValue('id', 'int', 'POST', 0);
     // id chien dich
     if (!$promo_id) {
         //lỗi không tồn tại id của khuyến mại
         $array_return['error'] = 0;
         $array_return['msg'] = 'Bản ghi không tồn tại';
         die(json_encode($array_return));
     }
     // ten chien dich khuyen mai
     $promo_name = getValue('name', 'str', 'POST', '', 2);
     if (!$promo_name) {
         //lỗi chưa nhập tên chiến dịch km
         $array_return['error'] = 0;
         $array_return['msg'] = 'Chưa nhập tên chiến dịch khuyến mại';
         die(json_encode($array_return));
     }
     $promo_agencies = getValue('agencies', 'int', 'POST', 0, 3);
     if (!$promo_agencies) {
         //lỗi chưa nhập tên chiến dịch km
         $array_return['error'] = 0;
         $array_return['msg'] = 'Chưa chọn cửa hàng áp dụng khuyến mại';
         die(json_encode($array_return));
     }
     // thoi gian bat dau
     $start_time = getValue('start_date', 'str', 'POST', '', 3);
     $time_start_h = getValue('time_start_h', 'int', 'POST', 0, 3);
     $time_start_i = getValue('time_start_i', 'int', 'POST', 0, 3);
     //thoi gian ket thuc
     $end_time = getValue('end_date', 'str', 'POST', '');
     $time_end_h = getValue('time_end_h', 'int', 'POST', 0, 3);
     $time_end_i = getValue('time_end_i', 'int', 'POST', 0, 3);
     // ghi chú
     $promo_note = getValue('note', 'str', 'POST', '');
     $list_menus = getValue('menus', 'arr', 'POST', array());
     // dieu kien giam gia
     $promo_condition = getValue('condition', 'str', 'POST', 0, 3);
     // gia tri giảm giá hóa đơn dựa vào kiểu giảm giá promo_type có 2 giá trị là % và tiền mặt
     $promo_value = getValue('promo_value', 'int', 'POST', 0, 3);
     $promo_type = getValue('promo_type', 'int', 'POST', 0, 3);
     $time_start = convertDateTime($start_time, $time_start_h . ':' . $time_start_i . ':0');
     if (!$time_start) {
         $array_return['error'] = 0;
         $array_return['msg'] = 'Chưa nhập thời gian bắt đầu chiến dịch';
         die(json_encode($array_return));
     }
     $time_end = convertDateTime($end_time, $time_end_h . ':' . $time_end_i . ':0');
     if (!$time_end) {
         $array_return['error'] = 0;
         $array_return['msg'] = 'Chưa nhập thời gian kết thúc chiến dịch';
         die(json_encode($array_return));
     }
     // ket quả tra ve
     // update chiến dịch khuyến mãi
     $myform = new generate_form();
     $myform->addTable('promotions');
     $myform->add('pms_name', 'name', 0, 0, $promo_name, 1, 'Bạn chưa nhập tên chiến dịch');
     $myform->add('pms_agency_id', 'agencies', 1, 0, $promo_agencies, 1, 'Bạn chưa chọn địa điểm áp dụng');
     $myform->add('pms_start_time', 'time_start', 0, 1, $time_start, 1, 'Thời gian bắt đầu chưa nhập');
     $myform->add('pms_end_time', 'time_end', 0, 1, $time_end, 1, 'Thời gian kết thúc chưa nhập');
     $myform->add('pms_value_sale', 'promo_value', 1, 0, $promo_value, 0);
     $myform->add('pms_type_sale', 'promo_type', 1, 0, $promo_type, 0);
     $myform->add('pms_condition', 'condition', 1, 0, $promo_condition, 0);
     $myform->add('pms_note', 'note', 0, 0, $promo_note, 0);
     if (!$myform->checkdata()) {
         $db_update = new db_execute($myform->generate_update_SQL('pms_id', $promo_id));
         //echo $myform->generate_update_SQL('pms_id', $promo_id);
         unset($db_update);
         //log action
         log_action(ACTION_LOG_ADD, 'Chỉnh sửa bản ghi ' . $promo_id . ' bảng promotions');
     }
     //xóa hết các thực đơn có trong chiến dịch khuyến mãi đang sửa và sau đó insert lại danh sách các thực đơn bổ sung
     $db_delete = new db_execute('DELETE FROM promotions_menu WHERE pms_id = ' . $promo_id . '');
     unset($db_delete);
     // insert lại những thực đơn cập nhập
     $db_insert = 'INSERT INTO promotions_menu(pms_id ,pms_menu_id, pms_menu_value, pms_menu_type)
                        VALUES';
     //sử dụng id của promotion để insert vào bảng promotions_menu
     foreach ($list_menus as $menu) {
         $db_insert .= '(
                        ' . $promo_id . ',
                        ' . $menu['men_id'] . ',
                        ' . $menu['men_value'] . ',
                        ' . $menu['men_type'] . '
                        ),';
     }
     $db_insert = rtrim($db_insert, ',');
     $db_insert_menu = new db_execute($db_insert);
     unset($db_insert_menu);
     // trả về kết quả thành công
     $array_return['success'] = 1;
     $array_return['msg'] = 'Cập nhật thành công';
     die(json_encode($array_return));
 }
Example #19
0
<?php

require 'inc_security.php';
$record_id = getValue('record_id');
$listGender = array();
$listGender[0] = '-- Giới tính --';
$listGender[1] = 'Nam';
$listGender[2] = 'Nữ';
$listGender[3] = 'Khác';
$use_birthday = getValue('use_birthday', 'str', 'POST', '');
$use_birthday = convertDateTime($use_birthday);
$myform = new generate_form();
$myform->removeHTML(0);
$myform->add('use_email', 'use_email', 0, 0, '', 1, 'Lỗi nhập email', 0, 'Trùng email');
$myform->add('use_name', 'use_email', 0, 0, '', 1, 'Lỗi nhập email', 0, 'Trùng email');
$myform->add('use_firstname', 'use_firstname', 0, 0, '', 1, 'Bạn chưa nhập họ', 0);
$myform->add('use_lastname', 'use_lastname', 0, 0, '', 1, 'Bạn chưa nhập tên', 0);
$myform->add('use_birthday', 'use_birthday', 0, 1, '', 1, 'Bạn chưa nhập ngày sinh', 0);
$myform->add('use_phone', 'use_phone', 1, 0, 0, 1, 'Bạn chưa nhập số điện thoại', 0);
$myform->add('use_contact', 'use_contact', 0, 0, '', 1, 'Bạn chưa nhập địa chỉ', 0);
$myform->add('use_gender', 'use_gender', 1, 0, 0, 0, '', 0, '');
$myform->add('use_date', 'use_date', 1, 1, 0, 0, '', 0, '');
$myform->add('use_active', 'use_active', 1, 0, 0, 0, '', 0, '');
$myform->add('use_group', 'use_group', 1, 1, 0, 0, '', 0, '');
$myform->removeHTML(0);
$myform->addTable($bg_table);
$action = getValue('action', 'str', 'POST', '');
if ($action == 'execute') {
    $bg_errorMsg .= $myform->checkdata();
    $upload = new upload('use_avatar', $bg_filepath, $bg_extension, $limit_size);
    $filename = $upload->file_name;
Example #20
0
 function importProduct()
 {
     //check quyền
     checkCustomPermission('NHAP_HANG');
     global $admin_id, $configuration;
     $array_return = array();
     //kiểm tra xem có hóa đơn nào thực hiện ko, nếu có thì exit luôn
     $db_trigger = new db_query('SELECT tri_status FROM triggers WHERE tri_key = "billSubmit" LIMIT 1');
     $trigger = mysqli_fetch_assoc($db_trigger->result);
     unset($db_trigger);
     if ($trigger['tri_status'] == 1) {
         //đang có hóa đơn được thanh toán, exit luôn
         $array_return['error'] = 'Đang có hóa đơn khác được thanh toán, bạn vui lòng thử lại trong giây lát!';
         $this->add($array_return);
         return false;
     }
     //Không có hóa đơn nào đang được xử lý - cập nhật trigger status thành 1 để bắt đầu vào hàm
     $db_update = new db_execute('UPDATE triggers SET tri_status = 1 WHERE tri_key = "billSubmit" LIMIT 1');
     unset($db_update);
     $list_product = getValue('products', 'arr', 'POST', array());
     //loại thanh toán
     $pay_type = getValue('pay_type', 'int', 'POST', 0);
     if ($pay_type !== PAY_TYPE_CASH) {
         $pay_type = PAY_TYPE_CARD;
     }
     //tính tổng tiền cần thanh toán của hóa đơn
     $bio_total_money = 0;
     foreach ($list_product as $product) {
         $bio_total_money += $product['pro_number'] * $product['pro_price'];
     }
     //insert vào bảng hóa đơn nhập hàng bill_out
     //thời gian nhập hàng
     $bio_start_time = getValue('start_date', 'int', 'POST', 0);
     //kho hàng
     $bio_store_id = getValue('store_id', 'int', 'POST', 0);
     //Trạng thái hóa đơn - ghi nợ hay đã thanh toán đủ
     $is_debit = getValue('is_debit', 'int', 'POST', 0);
     $money_debit = getValue('money_debit', 'int', 'POST', 0);
     $date_debit = getValue('date_debit', 'str', 'POST', 0, 3);
     $date_debit_convert = convertDateTime($date_debit);
     if ($is_debit) {
         if ($date_debit_convert <= time()) {
             //thời gian trả nợ không phù hợp
             $array_return['error'] = 'Thời gian hẹn trả không phù hợp!';
             $this->add($array_return);
             return false;
         }
         if ($money_debit <= 0 || $money_debit > $bio_total_money) {
             $array_return['error'] = 'Số tiền trả trước không phù hợp!';
             $this->add($array_return);
             return false;
         }
         if ($money_debit == $bio_total_money) {
             //thanh toán hết
             $is_debit = 0;
         }
     }
     //trạng thái thanh toán hóa đơn
     $bio_status = $is_debit ? BILL_STATUS_DEBIT : BILL_STATUS_SUCCESS;
     if ($bio_status == BILL_STATUS_DEBIT) {
         //gửi lên money_debit là số tiền trả trước
         //khi lưu vào bio_money_debit ta lưu số tiền còn nợ
         $bio_money_debit = $bio_total_money - $money_debit;
         $bio_date_debit = $date_debit_convert;
     } else {
         $bio_money_debit = 0;
         $bio_date_debit = 0;
     }
     //nhà cung cấp
     $bio_supplier_id = getValue('supplier', 'int', 'POST', 0);
     //check nhà cung cấp
     if (!$bio_supplier_id) {
         $array_return['error'] = 'Bạn chưa chọn nhà cung cấp!';
         $this->add($array_return);
         return false;
     }
     //ghi chú
     $bio_note = getValue('note', 'str', 'POST', '', 3);
     //người nhập hàng
     $bio_admin_id = $admin_id;
     $sql_insert = 'INSERT INTO bill_out (bio_start_time,
                                          bio_store_id,
                                          bio_status,
                                          bio_total_money,
                                          bio_supplier_id,
                                          bio_note,
                                          bio_type,
                                          bio_admin_id,
                                          bio_money_debit,
                                          bio_date_debit)
                    VALUES (
                    ' . $bio_start_time . ',
                    ' . $bio_store_id . ',
                    ' . $bio_status . ',
                    ' . $bio_total_money . ',
                    ' . $bio_supplier_id . ',
                    "' . $bio_note . '",
                    ' . $pay_type . ',
                    ' . $bio_admin_id . ',
                    ' . $bio_money_debit . ',
                    ' . $bio_date_debit . '
                    )';
     $db_insert = new db_execute_return();
     //echo $sql_insert;
     $last_id = $db_insert->db_execute($sql_insert);
     unset($db_insert);
     if (!$last_id) {
         //lỗi
         $array_return = array('error' => 'Đã có lỗi xảy ra! Vui lòng thử lại sau');
         echo json_encode($array_return);
         exit;
     }
     //sử dụng id của hóa đơn để insert vào bảng bill_out_detail
     foreach ($list_product as $product) {
         //mã hóa đơn
         $bid_bill_id = $last_id;
         //mã mặt hàng
         $bid_pro_id = $product['pro_id'];
         //số lượng
         $bid_pro_number = $product['pro_number'];
         //giá nhập
         $bid_pro_price = $product['pro_price'];
         $sql_insert = 'INSERT INTO bill_out_detail (bid_bill_id, bid_pro_id, bid_pro_number, bid_pro_price)
                        VALUES (
                        ' . $bid_bill_id . ',
                        ' . $bid_pro_id . ',
                        ' . $bid_pro_number . ',
                        ' . $bid_pro_price . '
                        )';
         $db_insert = new db_execute($sql_insert);
         unset($db_insert);
         //cộng số lượng vào kho
         //nếu không có bản ghi nào thì insert, không thì update
         $db_update = new db_execute('INSERT INTO product_quantity (product_id,store_id,pro_quantity)
                                      VALUES(' . $bid_pro_id . ',' . $bio_store_id . ',' . $bid_pro_number . ')
                                      ON DUPLICATE KEY UPDATE pro_quantity = pro_quantity + ' . $bid_pro_number);
         unset($db_update);
     }
     //insert 1 phiếu chi
     $fin_date = time();
     $fin_updated_time = time();
     //số tiền chi
     $fin_money = $bio_total_money;
     //nếu ghi nợ thì số tiền chi bằng số tiền trả trước
     if ($bio_status == BILL_STATUS_DEBIT) {
         $fin_money = $money_debit;
     }
     //lý do chi
     $fin_reason_other = 'Nhập hàng';
     //mã hóa đơn nhập hàng
     $fin_billcode = $last_id;
     //lấy thong tin nhà cung cấp
     $db_sup = new db_query('SELECT * FROM suppliers WHERE sup_id = ' . $bio_supplier_id . ' LIMIT 1');
     $supplier_data = mysqli_fetch_assoc($db_sup->result);
     unset($db_sup);
     $fin_username = $supplier_data['sup_name'];
     $fin_address = $supplier_data['sup_address'];
     $fin_cat_id = FINANCIAL_CAT_NHAP_HANG;
     $fin_pay_type = $pay_type;
     $fin_note = $bio_note;
     $fin_admin_id = $admin_id;
     $fin_agency_id = $configuration['con_default_agency'];
     //insert vào bảng financial
     $sql_insert = 'INSERT INTO financial (fin_date, fin_updated_time, fin_money, fin_reason_other, fin_billcode, fin_username, fin_address, fin_cat_id, fin_pay_type, fin_note, fin_admin_id, fin_agency_id)
                    VALUES (
                    ' . $fin_date . ',
                    ' . $fin_updated_time . ',
                    ' . $fin_money . ',
                    "' . $fin_reason_other . '",
                    "' . $fin_billcode . '",
                    "' . $fin_username . '",
                    "' . $fin_address . '",
                    ' . $fin_cat_id . ',
                    ' . $fin_pay_type . ',
                    "' . $fin_note . '",
                    ' . $fin_admin_id . ',
                    ' . $fin_agency_id . '
                    )';
     $db_insert = new db_execute_return();
     $fin_insert_id = $db_insert->db_execute($sql_insert);
     //thực hiện update trigger về 0 để giải phóng function
     $db_update = new db_execute('UPDATE triggers SET tri_status = 0 WHERE tri_key = "billSubmit" LIMIT 1');
     unset($db_update);
     if (!$fin_insert_id) {
         //lỗi
         $array_return = array('error' => 'Đã có lỗi xảy ra! Vui lòng thử lại sau');
         echo json_encode($array_return);
         exit;
     } else {
         $array_return = array('success' => 1, 'fin_id' => $fin_insert_id, 'bio_id' => $last_id);
         echo json_encode($array_return);
         exit;
     }
 }