function Output($params)
 {
     global $db, $currencies;
     if (count($params) != $this->size_params) {
         //upgrading
         $params = $this->Upgrade($params);
     }
     $list_length = array();
     $contents = '';
     $control = '';
     for ($i = 0; $i <= $this->max_length; $i++) {
         $list_length[] = array('id' => $i, 'text' => $i);
     }
     // Build control box form data
     $control = '<div class="row">';
     $control .= '<div style="white-space:nowrap">' . TEXT_SHOW . TEXT_SHOW_NO_LIMIT;
     $control .= html_pull_down_menu('to_receive_inv_field_0', $list_length, $params['num_rows']);
     $control .= html_submit_field('sub_to_receive_inv', TEXT_SAVE);
     $control .= '</div></div>';
     // Build content box
     $total = 0;
     $sql = "select id, purchase_invoice_id, total_amount, bill_primary_name, currencies_code, currencies_value, post_date, journal_id \n\t\t  from " . TABLE_JOURNAL_MAIN . " \n\t\t  where journal_id in (6,7) and waiting = '1' order by post_date DESC, purchase_invoice_id DESC";
     if ($params['num_rows']) {
         $sql .= " limit " . $params['num_rows'];
     }
     $result = $db->Execute($sql);
     if ($result->RecordCount() < 1) {
         $contents = ACT_NO_RESULTS;
     } else {
         while (!$result->EOF) {
             $inv_balance = $result->fields['total_amount'] - fetch_partially_paid($result->fields['id']);
             if ($result->fields['journal_id'] == 7) {
                 $inv_balance = -$inv_balance;
             }
             $total += $inv_balance;
             $contents .= '<div style="float:right">' . $currencies->format_full($inv_balance, true, $result->fields['currencies_code'], $result->fields['currencies_value']) . '</div>';
             $contents .= '<div>';
             $contents .= '<a href="' . html_href_link(FILENAME_DEFAULT, "module=phreebooks&amp;page=orders&amp;oID={$result->fields['id']}&amp;jID={$result->fields['journal_id']}&amp;action=edit", 'SSL') . '">';
             $contents .= gen_locale_date($result->fields['post_date']) . ' - ';
             if ($result->fields['purchase_invoice_id'] != '') {
                 $contents .= $result->fields['purchase_invoice_id'] . ' - ';
             }
             $contents .= htmlspecialchars($result->fields['bill_primary_name']);
             $contents .= '</a></div>' . chr(10);
             $result->MoveNext();
         }
     }
     if (!$params['num_rows'] && $result->RecordCount() > 0) {
         $contents .= '<div style="float:right">' . $currencies->format_full($total, true, DEFAULT_CURRENCY, 1) . '</div>';
         $contents .= '<div><b>' . TEXT_TOTAL . '</b></div>' . chr(10);
     }
     return $this->build_div('', $contents, $control);
 }
예제 #2
0
$idx = 1;
while (!$query_result->EOF) {
    $due_dates = calculate_terms_due_dates($query_result->fields['post_date'], $query_result->fields['terms'], 'AP');
    if ($due_dates['net_date'] > $invoice_date && ($due_dates['early_date'] > $discount_date || $due_dates['discount'] == 0)) {
        $query_result->MoveNext();
        continue;
        // skip if not within selected discount window
    }
    if ($invoice_date < $due_dates['net_date']) {
        if ($discount_date < $due_dates['early_date']) {
            $query_result->MoveNext();
            continue;
            // skip if not within selected discount window
        }
    }
    $already_paid = fetch_partially_paid($query_result->fields['id']);
    $amount_due = $query_result->fields['total_amount'] - $already_paid;
    if ($query_result->fields['journal_id'] == 7) {
        $amount_due = -$amount_due;
    }
    // vendor credit memos
    $discount = $currencies->format(($query_result->fields['total_amount'] - $already_paid) * $due_dates['discount']);
    if ($post_date > $due_dates['early_date']) {
        $discount = 0;
    }
    // past the early date
    $extra_params = $query_result->fields['waiting'] == '1' ? 'readonly="readonly" ' : '';
    echo '<tr' . ($extra_params ? ' class="ui-state-error"' : '') . '>' . chr(10);
    echo '<td align="center">' . chr(10);
    echo gen_locale_date($query_result->fields['post_date']) . chr(10);
    // Hidden fields
예제 #3
0
function fill_paid_invoice_array($id, $account_id, $type = 'c')
{
    // to build this data array, all current open invoices need to be gathered and then the paid part needs
    // to be applied along with discounts taken by row.
    global $db, $currencies;
    $negate = JOURNAL_ID == 20 && $type == 'c' || JOURNAL_ID == 18 && $type == 'v' ? true : false;
    // first read all currently open invoices and the payments of interest and put into an array
    $sql = "select distinct so_po_item_ref_id from " . TABLE_JOURNAL_ITEM . " where ref_id = " . $id;
    $result = $db->Execute($sql);
    $paid_indeces = array();
    while (!$result->EOF) {
        if ($result->fields['so_po_item_ref_id']) {
            $paid_indeces[] = $result->fields['so_po_item_ref_id'];
        }
        $result->MoveNext();
    }
    switch ($type) {
        case 'c':
            $search_journal = '(12, 13)';
            break;
        case 'v':
            $search_journal = '(6, 7)';
            break;
        default:
            return false;
    }
    $sql = "select id, journal_id, post_date, terms, purch_order_id, purchase_invoice_id, total_amount, gl_acct_id \r\n\t\tfrom " . TABLE_JOURNAL_MAIN . " \r\n\t\twhere (journal_id in " . $search_journal . " and closed = '0' and bill_acct_id = " . $account_id . ")";
    if (sizeof($paid_indeces) > 0) {
        $sql .= " or (id in (" . implode(',', $paid_indeces) . ") and closed = '0')";
    }
    $sql .= " order by post_date";
    $result = $db->Execute($sql);
    $open_invoices = array();
    while (!$result->EOF) {
        if ($result->fields['journal_id'] == 7 || $result->fields['journal_id'] == 13) {
            $result->fields['total_amount'] = -$result->fields['total_amount'];
        }
        $result->fields['total_amount'] -= fetch_partially_paid($result->fields['id']);
        $result->fields['description'] = $result->fields['purch_order_id'];
        $result->fields['discount'] = '';
        $result->fields['amount_paid'] = '';
        $open_invoices[$result->fields['id']] = $result->fields;
        $result->MoveNext();
    }
    // next read the record of interest and add/adjust open invoice array with amounts
    $sql = "select id, ref_id, so_po_item_ref_id, gl_type, description, debit_amount, credit_amount, gl_account \r\n\t\tfrom " . TABLE_JOURNAL_ITEM . " where ref_id = " . $id;
    $result = $db->Execute($sql);
    while (!$result->EOF) {
        $amount = $result->fields['debit_amount'] ? $result->fields['debit_amount'] : $result->fields['credit_amount'];
        if ($negate) {
            $amount = -$amount;
        }
        $index = $result->fields['so_po_item_ref_id'];
        switch ($result->fields['gl_type']) {
            case 'dsc':
                // it's the discount field
                $open_invoices[$index]['discount'] = $amount;
                $open_invoices[$index]['amount_paid'] -= $amount;
                break;
            case 'chk':
            case 'pmt':
                // it's the payment field
                $open_invoices[$index]['total_amount'] += $amount;
                $open_invoices[$index]['description'] = $result->fields['description'];
                $open_invoices[$index]['amount_paid'] = $amount;
                break;
            case 'ttl':
                $payment_fields = $result->fields['description'];
                // payment details
            // payment details
            default:
        }
        $result->MoveNext();
    }
    ksort($open_invoices);
    $balance = 0;
    $index = 0;
    $item_list = array();
    foreach ($open_invoices as $key => $line_item) {
        // fetch some information about the invoice
        $sql = "select id, post_date, terms, purchase_invoice_id, purch_order_id, gl_acct_id, waiting  \r\n\t\t\tfrom " . TABLE_JOURNAL_MAIN . " where id = " . $key;
        $result = $db->Execute($sql);
        $due_dates = calculate_terms_due_dates($result->fields['post_date'], $result->fields['terms'], $type == 'v' ? 'AP' : 'AR');
        if ($negate) {
            $line_item['total_amount'] = -$line_item['total_amount'];
            $line_item['discount'] = -$line_item['discount'];
            $line_item['amount_paid'] = -$line_item['amount_paid'];
        }
        $balance += $line_item['total_amount'];
        $item_list[] = array('id' => $result->fields['id'], 'waiting' => $result->fields['waiting'], 'purchase_invoice_id' => $result->fields['purchase_invoice_id'], 'purch_order_id' => $result->fields['purch_order_id'], 'percent' => $due_dates['discount'], 'early_date' => gen_spiffycal_db_date_short($due_dates['early_date']), 'net_date' => gen_spiffycal_db_date_short($due_dates['net_date']), 'total_amount' => $currencies->format($line_item['total_amount']), 'gl_acct_id' => $result->fields['gl_acct_id'], 'description' => $line_item['description'], 'discount' => $line_item['discount'] ? $currencies->format($line_item['discount']) : '', 'amount_paid' => $line_item['amount_paid'] ? $currencies->format($line_item['amount_paid']) : '');
        $index++;
    }
    return array('balance' => $balance, 'payment_fields' => $payment_fields, 'invoices' => $item_list);
}
예제 #4
0
         $messageStack->add(GL_ERROR_NEVER_POSTED, 'error');
     }
     $messageStack->add(GL_ERROR_NO_DELETE, 'error');
     // if we are here, there was an error, reload page
     $order = new objectInfo($_POST);
     $order->post_date = gen_db_date($_POST['post_date']);
     // fix the date to original format
     break;
 case 'pmt':
     // for opening a sales/invoice directly from payment (POS like)
     // fetch the journal_main information
     $sql = "select id, shipper_code, bill_acct_id, bill_address_id, bill_primary_name, bill_contact, bill_address1, \n\t\tbill_address2, bill_city_town, bill_state_province, bill_postal_code, bill_country_code, bill_email, \n\t\tpost_date, terms, gl_acct_id, purchase_invoice_id, total_amount from " . TABLE_JOURNAL_MAIN . " \n\t\twhere id = " . $oID;
     $result = $db->Execute($sql);
     $account_id = $db->Execute("select short_name from " . TABLE_CONTACTS . " where id = " . $result->fields['bill_acct_id']);
     $due_dates = calculate_terms_due_dates($result->fields['post_date'], $result->fields['terms'], 'AR');
     $pre_paid = fetch_partially_paid($oID);
     $order->bill_acct_id = $result->fields['bill_acct_id'];
     $order->bill_primary_name = $result->fields['bill_primary_name'];
     $order->bill_contact = $result->fields['bill_contact'];
     $order->bill_address1 = $result->fields['bill_address1'];
     $order->bill_address2 = $result->fields['bill_address2'];
     $order->bill_city_town = $result->fields['bill_city_town'];
     $order->bill_state_province = $result->fields['bill_state_province'];
     $order->bill_postal_code = $result->fields['bill_postal_code'];
     $order->bill_country_code = $result->fields['bill_country_code'];
     $order->bill_email = $result->fields['bill_email'];
     $order->id_1 = $result->fields['id'];
     $order->inv_1 = $result->fields['purchase_invoice_id'];
     $order->acct_1 = $result->fields['gl_acct_id'];
     $order->early_1 = $due_dates['early_date'];
     $order->due_1 = $due_dates['net_date'];
예제 #5
0
 private function get_all_open_invoices()
 {
     // to build this data array, all current open invoices need to be gathered and then the paid part needs
     // to be applied along with discounts taken by row.
     global $db, $currencies;
     $sql = "select m.id as id, m.journal_id as journal_id, m.post_date as post_date, m.terms as terms, m.purch_order_id as purch_order_id, i.debit_amount as debit_amount, i.credit_amount as credit_amount,\n\t\t m.purchase_invoice_id as purchase_invoice_id, m.total_amount as total_amount, m.gl_acct_id as gl_acct_id, m.bill_acct_id as bill_acct_id, c.type as type, c.short_name as short_name, m.waiting as waiting  \n\t\t  from " . TABLE_JOURNAL_MAIN . " m join " . TABLE_CONTACTS . " c on m.bill_acct_id = c.id join " . TABLE_JOURNAL_ITEM . " i on m.id = i.ref_id\n\t\t  where journal_id in (6, 7, 12, 13) and closed = '0' and gl_type = 'ttl'";
     $sql .= " order by m.post_date";
     $result = $db->Execute($sql);
     $open_invoices = array();
     while (!$result->EOF) {
         $result->fields['total_amount'] = $result->fields['debit_amount'] ? $result->fields['debit_amount'] : $result->fields['credit_amount'];
         $result->fields['total_amount'] -= fetch_partially_paid($result->fields['id']);
         if ($result->fields['journal_id'] == 7 || $result->fields['journal_id'] == 13) {
             $result->fields['total_amount'] = -$result->fields['total_amount'];
         }
         $result->fields['description'] = $result->fields['purch_order_id'];
         $result->fields['discount'] = '';
         $result->fields['amount_paid'] = '';
         $open_invoices[$result->fields['id']] = $result->fields;
         $result->MoveNext();
     }
     ksort($open_invoices);
     $balance = 0;
     $index = 0;
     foreach ($open_invoices as $key => $line_item) {
         // fetch some information about the invoice
         $due_dates = calculate_terms_due_dates($line_item['post_date'], $line_item['terms'], $line_item['type'] == 'v' ? 'AP' : 'AR');
         $negate = $line_item['journal_id'] == 20 && $line_item['type'] == 'c' || $line_item['journal_id'] == 18 && $line_item['type'] == 'v' ? true : false;
         if ($negate) {
             $line_item['total_amount'] = -$line_item['total_amount'];
             $line_item['discount'] = -$line_item['discount'];
             $line_item['amount_paid'] = -$line_item['amount_paid'];
         }
         $balance += $line_item['total_amount'];
         $this->open_inv[$line_item['bill_acct_id']][$line_item['id']] = array('id' => $line_item['id'], 'waiting' => $line_item['waiting'], 'purchase_invoice_id' => $line_item['purchase_invoice_id'], 'purch_order_id' => $line_item['purch_order_id'], 'percent' => $due_dates['discount'], 'post_date' => $line_item['post_date'], 'early_date' => $due_dates['early_date'], 'net_date' => $due_dates['net_date'], 'total_amount' => round($line_item['total_amount'], $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']), 'gl_acct_id' => $line_item['gl_acct_id'], 'description' => $line_item['description'], 'type' => $line_item['type'], 'short_name' => $line_item['short_name'], 'discount' => round($line_item['discount'], $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']), 'amount_paid' => round($line_item['amount_paid'], $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']));
         $index++;
     }
 }