예제 #1
0
function handle_submit(&$selected_id)
{
    global $path_to_root, $Ajax, $auto_create_branch;
    if (!can_process()) {
        return;
    }
    if ($selected_id) {
        update_customer($_POST['customer_id'], $_POST['CustName'], $_POST['cust_ref'], $_POST['address'], $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['credit_status'], $_POST['payment_terms'], input_num('discount') / 100, input_num('pymt_discount') / 100, input_num('credit_limit'), $_POST['sales_type'], $_POST['notes']);
        update_record_status($_POST['customer_id'], $_POST['inactive'], 'debtors_master', 'debtor_no');
        $Ajax->activate('customer_id');
        // in case of status change
        display_notification(_("Customer has been updated."));
    } else {
        //it is a new customer
        begin_transaction();
        add_customer($_POST['CustName'], $_POST['cust_ref'], $_POST['address'], $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['credit_status'], $_POST['payment_terms'], input_num('discount') / 100, input_num('pymt_discount') / 100, input_num('credit_limit'), $_POST['sales_type'], $_POST['notes']);
        $selected_id = $_POST['customer_id'] = db_insert_id();
        if (isset($auto_create_branch) && $auto_create_branch == 1) {
            add_branch($selected_id, $_POST['CustName'], $_POST['cust_ref'], $_POST['address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], get_company_pref('default_sales_act'), get_company_pref('default_sales_discount_act'), get_company_pref('debtors_act'), get_company_pref('default_prompt_payment_act'), $_POST['location'], $_POST['address'], 0, 0, $_POST['ship_via'], $_POST['notes']);
            $selected_branch = db_insert_id();
            add_crm_person($_POST['CustName'], $_POST['cust_ref'], '', $_POST['address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], '', '');
            $pers_id = db_insert_id();
            add_crm_contact('cust_branch', 'general', $selected_branch, $pers_id);
            add_crm_contact('customer', 'general', $selected_id, $pers_id);
        }
        commit_transaction();
        display_notification(_("A new customer has been added."));
        if (isset($auto_create_branch) && $auto_create_branch == 1) {
            display_notification(_("A default Branch has been automatically created, please check default Branch values by using link below."));
        }
        $Ajax->activate('_page_body');
    }
}
예제 #2
0
function write_customer($email, $name, $company, $address, $phone, $fax, $currency)
{
    global $paypal_sales_type_id, $paypal_tax_group_id, $paypal_salesman, $paypal_area, $paypal_location, $paypal_credit_status, $paypal_shipper;
    global $SysPrefs;
    log_message("Memory, write_customer start:" . memory_get_usage());
    $customer_id = find_customer_by_email($email);
    if (empty($customer_id)) {
        $customer_id = find_customer_by_name($company);
    }
    if (empty($customer_id)) {
        //it is a new customer
        begin_transaction();
        add_customer($company, substr($company, 0, 30), $address, '', $currency, 0, 0, $paypal_credit_status, -1, 0, 0, $SysPrefs->default_credit_limit(), $paypal_sales_type_id, 'PayPal');
        $customer_id = db_insert_id();
        add_branch($customer_id, $company, substr($company, 0, 30), $address, $paypal_salesman, $paypal_area, $paypal_tax_group_id, '', get_company_pref('default_sales_discount_act'), get_company_pref('debtors_act'), get_company_pref('default_prompt_payment_act'), $paypal_location, $address, 0, 0, $paypal_shipper, 'PayPal');
        $selected_branch = db_insert_id();
        $nameparts = explode(" ", $name);
        $firstname = "";
        for ($i = 0; $i < count($nameparts) - 1; $i++) {
            if (!empty($firstname)) {
                $firstname .= " ";
            }
            $firstname .= $nameparts[$i];
        }
        $lastname = $nameparts[count($nameparts) - 1];
        add_crm_person('paypal', $firstname, $lastname, $address, $phone, '', $fax, $email, '', '');
        add_crm_contact('customer', 'general', $selected_branch, db_insert_id());
        commit_transaction();
    } else {
        $selected_branch = 0;
    }
    log_message("Memory, write_customer end:" . memory_get_usage());
    return array($customer_id, $selected_branch);
}
예제 #3
0
function create_member($gatech_email, $first_name, $last_name, $password)
{
    $insert_member = <<<SQL
insert into tb_member
            (
              first_name,
              last_name,
              gatech_email_address,
              display_email_address,
              password_hash
            )
     values (
              ?first_name?,
              ?last_name?,
              ?gatech_email?,
              ?gatech_email?,
              crypt( ?password?, gen_salt( 'bf' ) )
            )
  returning member
SQL;
    $params = ['first_name' => $first_name, 'last_name' => $last_name, 'gatech_email' => $gatech_email, 'password' => $password];
    begin_transaction();
    $insert = query_execute($insert_member, $params);
    if (query_success($insert)) {
        $member_created = query_fetch_one($insert);
        $member_pk = $member_created['member'];
        $insert_role = <<<SQL
insert into tb_member_role
            (
              member,
              role
            )
     values (
              ?member?,
              ?role?
            )
SQL;
        $params = ['member' => $member_pk, 'role' => ROLE_MEMBER];
        $result = query_execute($insert_role, $params);
        if (query_success($result)) {
            commit_transaction();
            return $member_pk;
        }
    }
    rollback_transaction();
    return false;
}
예제 #4
0
function handle_process()
{
    begin_transaction();
    // clear all the allocations for this payment/credit
    clear_cust_alloctions($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no);
    // now add the new allocations
    $total_allocated = 0;
    foreach ($_SESSION['alloc']->allocs as $allocn_item) {
        if ($allocn_item->current_allocated > 0) {
            add_cust_allocation($allocn_item->current_allocated, $_SESSION['alloc']->type, $_SESSION['alloc']->trans_no, $allocn_item->type, $allocn_item->type_no, $_SESSION['alloc']->date_);
            update_debtor_trans_allocation($allocn_item->type, $allocn_item->type_no, $allocn_item->current_allocated);
            $total_allocated += $allocn_item->current_allocated;
        }
    }
    /*end of the loop through the array of allocations made */
    update_debtor_trans_allocation($_SESSION['alloc']->type, $_SESSION['alloc']->trans_no, $total_allocated);
    commit_transaction();
    clear_allocations();
}
예제 #5
0
function handle_submit()
{
    global $path_to_root;
    if (!can_process()) {
        return;
    }
    if (!isset($_POST['New'])) {
        $sql = "UPDATE debtors_master SET name=" . db_escape($_POST['CustName']) . ", \n\t\t\taddress=" . db_escape($_POST['address']) . ", \n\t\t\ttax_id=" . db_escape($_POST['tax_id']) . ", \n\t\t\tcurr_code=" . db_escape($_POST['curr_code']) . ", \n\t\t\temail=" . db_escape($_POST['email']) . ", \n\t\t\tdimension_id=" . db_escape($_POST['dimension_id']) . ", \n\t\t\tdimension2_id=" . db_escape($_POST['dimension2_id']) . ", \n            credit_status=" . db_escape($_POST['credit_status']) . ", \n            payment_terms=" . db_escape($_POST['payment_terms']) . ", \n            discount=" . input_num('discount') / 100 . ", \n            pymt_discount=" . input_num('pymt_discount') / 100 . ", \n            credit_limit=" . input_num('credit_limit') . ", \n            sales_type = " . db_escape($_POST['sales_type']) . " \n            WHERE debtor_no = '" . $_POST['customer_id'] . "'";
        db_query($sql, "The customer could not be updated");
        display_notification(tr("Customer has been updated."));
        clear_fields();
    } else {
        //it is a new customer
        begin_transaction();
        $sql = "INSERT INTO debtors_master (name, address, tax_id, email, dimension_id, dimension2_id,  \n\t\t\tcurr_code, credit_status, payment_terms, discount, pymt_discount,credit_limit, \n\t\t\tsales_type) VALUES (" . db_escape($_POST['CustName']) . ", " . db_escape($_POST['address']) . ", " . db_escape($_POST['tax_id']) . "," . db_escape($_POST['email']) . ", " . db_escape($_POST['dimension_id']) . ", " . db_escape($_POST['dimension2_id']) . ", " . db_escape($_POST['curr_code']) . ", \n\t\t\t" . db_escape($_POST['credit_status']) . ", " . db_escape($_POST['payment_terms']) . ", " . input_num('discount') / 100 . ", \n\t\t\t" . input_num('pymt_discount') / 100 . ", " . input_num('credit_limit') . ", " . db_escape($_POST['sales_type']) . ")";
        db_query($sql, "The customer could not be added");
        $new_customer_id = db_insert_id();
        commit_transaction();
        display_notification(tr("A new customer has been added."));
        hyperlink_params($path_to_root . "/sales/manage/customer_branches.php", tr("Add branches for this customer"), "debtor_no={$new_customer_id}");
        clear_fields();
    }
}
예제 #6
0
        $input_error = 1;
    }
    return $input_error;
}
if (isset($_POST['Process']) && !check_trans()) {
    begin_transaction();
    $_SESSION['pay_items'] =& $_SESSION['pay_items'];
    $new = $_SESSION['pay_items']->order_id == 0;
    add_new_exchange_rate(get_bank_account_currency(get_post('bank_account')), get_post('date_'), input_num('_ex_rate'));
    $trans = write_bank_transaction($_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id, $_POST['bank_account'], $_SESSION['pay_items'], $_POST['date_'], $_POST['PayType'], $_POST['person_id'], get_post('PersonDetailID'), $_POST['ref'], $_POST['memo_'], true, input_num('settled_amount', null));
    $trans_type = $trans[0];
    $trans_no = $trans[1];
    new_doc_date($_POST['date_']);
    $_SESSION['pay_items']->clear_items();
    unset($_SESSION['pay_items']);
    commit_transaction();
    if ($new) {
        meta_forward($_SERVER['PHP_SELF'], $trans_type == ST_BANKPAYMENT ? "AddedID={$trans_no}" : "AddedDep={$trans_no}");
    } else {
        meta_forward($_SERVER['PHP_SELF'], $trans_type == ST_BANKPAYMENT ? "UpdatedID={$trans_no}" : "UpdatedDep={$trans_no}");
    }
}
//-----------------------------------------------------------------------------------------------
function check_item_data()
{
    if (!check_num('amount', 0)) {
        display_error(_("The amount entered is not a valid number or is less than zero."));
        set_focus('amount');
        return false;
    }
    if (isset($_POST['_ex_rate']) && input_num('_ex_rate') <= 0) {
예제 #7
0
function handle_commit_order()
{
    $cart =& $_SESSION['PO'];
    if (can_commit()) {
        copy_to_cart();
        if ($cart->trans_type != ST_PURCHORDER) {
            // for direct grn/invoice set same dates for lines as for whole document
            foreach ($cart->line_items as $line_no => $line) {
                $cart->line_items[$line_no]->req_del_date = $cart->orig_order_date;
            }
        }
        if ($cart->order_no == 0) {
            // new po/grn/invoice
            /*its a new order to be inserted */
            $ref = $cart->reference;
            if ($cart->trans_type != ST_PURCHORDER) {
                $cart->reference = 'auto';
                begin_transaction();
                // all db changes as single transaction for direct document
            }
            $order_no = add_po($cart);
            new_doc_date($cart->orig_order_date);
            $cart->order_no = $order_no;
            if ($cart->trans_type == ST_PURCHORDER) {
                unset($_SESSION['PO']);
                meta_forward($_SERVER['PHP_SELF'], "AddedID={$order_no}");
            }
            //Direct GRN
            if ($cart->trans_type == ST_SUPPRECEIVE) {
                $cart->reference = $ref;
            }
            if ($cart->trans_type != ST_SUPPINVOICE) {
                $cart->Comments = $cart->reference;
            }
            //grn does not hold supp_ref
            foreach ($cart->line_items as $key => $line) {
                $cart->line_items[$key]->receive_qty = $line->quantity;
            }
            $grn_no = add_grn($cart);
            if ($cart->trans_type == ST_SUPPRECEIVE) {
                commit_transaction();
                // save PO+GRN
                unset($_SESSION['PO']);
                meta_forward($_SERVER['PHP_SELF'], "AddedGRN={$grn_no}");
            }
            //			Direct Purchase Invoice
            $inv = new supp_trans(ST_SUPPINVOICE);
            $inv->Comments = $cart->Comments;
            $inv->supplier_id = $cart->supplier_id;
            $inv->tran_date = $cart->orig_order_date;
            $inv->due_date = $cart->due_date;
            $inv->reference = $ref;
            $inv->supp_reference = $cart->supp_ref;
            $inv->tax_included = $cart->tax_included;
            $supp = get_supplier($cart->supplier_id);
            $inv->tax_group_id = $supp['tax_group_id'];
            $inv->ov_amount = $inv->ov_gst = $inv->ov_discount = 0;
            $total = 0;
            foreach ($cart->line_items as $key => $line) {
                $inv->add_grn_to_trans($line->grn_item_id, $line->po_detail_rec, $line->stock_id, $line->item_description, $line->receive_qty, 0, $line->receive_qty, $line->price, $line->price, true, get_standard_cost($line->stock_id), '');
                $inv->ov_amount += round2($line->receive_qty * $line->price, user_price_dec());
            }
            $inv->tax_overrides = $cart->tax_overrides;
            if (!$inv->tax_included) {
                $taxes = $inv->get_taxes($inv->tax_group_id, 0, false);
                foreach ($taxes as $taxitem) {
                    $total += isset($taxitem['Override']) ? $taxitem['Override'] : $taxitem['Value'];
                }
            }
            $inv->ex_rate = $cart->ex_rate;
            $inv_no = add_supp_invoice($inv);
            commit_transaction();
            // save PO+GRN+PI
            // FIXME payment for cash terms. (Needs cash account selection)
            unset($_SESSION['PO']);
            meta_forward($_SERVER['PHP_SELF'], "AddedPI={$inv_no}");
        } else {
            // order modification
            $order_no = update_po($cart);
            unset($_SESSION['PO']);
            meta_forward($_SERVER['PHP_SELF'], "AddedID={$order_no}&Updated=1");
        }
    }
}
예제 #8
0
파일: index.php 프로젝트: enikesha/v_order
function route_post_order_action($local_id)
{
    global $MC_Text;
    if (!preg_match('/^\\d+$/', $local_id)) {
        status(HTTP_NOT_FOUND);
        exit;
    }
    $member = authOpenAPIMember();
    if ($member === FALSE) {
        status(HTTP_FORBIDDEN);
        exit;
    }
    $uid = $member['id'];
    $order = get_order($local_id);
    if ($order === FALSE) {
        status(HTTP_NOT_FOUND);
        exit;
    }
    $response = array();
    $act = $_POST['act'];
    switch ($act) {
        case 'cancel':
            if ($order['uid'] != $member['id']) {
                status(HTTP_FORBIDDEN);
                exit;
            }
            if (($order['flags'] & FLAG_DELETED) == FLAG_DELETED) {
                return json_error('ORDER_CANCELLED');
            }
            if (($order['flags'] & FLAG_REPLIED) == FLAG_REPLIED) {
                return json_error('ORDER_COMMITTED');
            }
            // Start and lock 'reverse-order' transaction
            $temp = start_order_transaction($uid, -$order['amount']);
            if ($temp === FALSE) {
                return json_error('START_TRANS');
            }
            // Set order 'DELETED' flag
            $res = $MC_Text->increment("flags-1_{$local_id}", FLAG_DELETED);
            if ($res === FALSE) {
                // Cancel transaction
                delete_temp_transaction($temp);
                return json_error('CANCEL_ORDER');
            }
            // Commit 'reverse-order' transaction
            commit_transaction($temp);
            $response['ok'] = TRUE;
            // Send to common queue
            enqueue(array('cancel' => $local_id), '');
            // Refresh balance
            $response['balance'] = formatBalance('USR', $uid);
            $response['order_balance'] = formatBalance('ORD', $uid);
            // Send to user's queue
            enqueue(array('cancel' => $local_id, 'balance' => $response['balance']), $uid);
            break;
        case 'commit':
            # Prevent from committing own orders
            #if ($order['uid'] == $member['id']) {
            #    status(HTTP_FORBIDDEN);
            #    exit;
            #}
            if (($order['flags'] & FLAG_DELETED) == FLAG_DELETED) {
                return json_error('ORDER_CANCELLED');
            }
            if (($order['flags'] & FLAG_REPLIED) == FLAG_REPLIED) {
                return json_error('ORDER_COMMITTED');
            }
            // Start and lock 'commit-order' transaction
            $temp = start_commit_order_transaction($uid, $order['uid'], $order['amount']);
            if ($temp === FALSE) {
                return json_error('START_TRANS');
            }
            // Set order 'COMMITTED' flag
            $resp = $MC_Text->increment("flags-1_{$local_id}", FLAG_REPLIED);
            if ($resp === FALSE) {
                // Cancel transaction
                delete_temp_transaction($temp);
                return json_error('COMMIT_ORDER');
            }
            // Commit 'commit-order' transaction
            $resp = commit_transaction($temp);
            # TODO: Store transaction id in the order
            $response['ok'] = TRUE;
            // Refresh balance
            $response['balance'] = formatBalance('USR', $uid);
            $response['order_balance'] = formatBalance('ORD', $uid);
            $author = $order['uid'];
            // Send to user's queue
            if ($uid != $author) {
                enqueue(array('commit' => $local_id, 'balance' => $response['balance']), $uid);
            }
            // Send to common queue
            enqueue(array('commit' => $local_id), '');
            // Render author's html
            global $i;
            global $page;
            $i = get_order($local_id);
            $page = array('member' => array('id' => $author));
            ob_start();
            include 'templates/_order.php';
            $html = ob_get_clean();
            // Send to author's queue
            $data = array('commit' => $local_id, 'order' => $i, 'html' => $html);
            if ($author == $uid) {
                $data['balance'] = $response['balance'];
            }
            enqueue($data, $author);
            break;
        default:
            status(HTTP_BAD_REQUEST);
            exit;
    }
    send_header('Content-Type: application/json; charset=utf-8');
    echo json_encode($response);
}