" . _("There are no line items that were retrieved for this invoice. A credit note cannot be created from this invoice."). "
";
- end_page();
- exit;
-
- }*/ //end of checks on returned data set
- db_free_result($result);
+ if (isset($_POST['Line'.$line_no.'Desc'])) {
+ $line_desc = $_POST['Line'.$line_no.'Desc'];
+ if (strlen($line_desc) > 0) {
+ $_SESSION['Items']->line_items[$line_no]->item_description = $line_desc;
+ }
+ }
}
- else
- {
- display_error(_("This invoice can not be credited using the automatic facility."));
- display_error("Please report that a duplicate debtor_trans header record was found for invoice " . $SESSION['InvoiceToCredit']);
- echo "
";
- exit;
- } //valid invoice record returned from the entered invoice number
+}
+//-----------------------------------------------------------------------------
+function copy_to_cart()
+{
+ $cart = &$_SESSION['Items'];
+ $cart->ship_via = $_POST['ShipperID'];
+ $cart->freight_cost = input_num('ChargeFreightCost');
+ $cart->document_date = $_POST['CreditDate'];
+ $cart->Location = $_POST['Location'];
+ $cart->Comments = $_POST['CreditText'];
}
-else
+//-----------------------------------------------------------------------------
+
+function copy_from_cart()
{
+ $cart = &$_SESSION['Items'];
+ $_POST['ShipperID'] = $cart->ship_via;
+ $_POST['ChargeFreightCost'] = price_format($cart->freight_cost);
+ $_POST['CreditDate']= $cart->document_date;
+ $_POST['Location']= $cart->Location;
+ $_POST['CreditText']= $cart->Comments;
+}
+//-----------------------------------------------------------------------------
-/* if processing, the page has been called and ${$StkItm->stock_id} would have been set from the post */
- foreach ($_SESSION['Items']->line_items as $itm)
- {
- $_SESSION['Items']->line_items[$itm->line_no]->qty_dispatched = $_POST[$itm->stock_id];
+if (isset($_POST['ProcessCredit']) && can_process()) {
- if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0)
- {
- $_SESSION['Items']->line_items[$itm->line_no]->item_description = $_POST[$itm->stock_id . "Desc"];
- }
- }
-}
+ $newcredit = ($_SESSION['Items']->trans_no == 0);
-//--------------------------------------------------------------------------------------
+ if (!isset($_POST['WriteOffGLCode']))
+ $_POST['WriteOffGLCode'] = 0;
-if (isset($_POST['ProcessCredit']))
-{
- process_credit();
+ copy_to_cart();
+ $credit_no = $_SESSION['Items']->write($_POST['WriteOffGLCode']);
+
+ processing_end();
+ if ($newcredit) {
+ meta_forward($_SERVER['PHP_SELF'], "AddedID=$credit_no");
+ } else {
+ meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$credit_no");
+ }
}
-//--------------------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
-if (isset($_POST['Location']))
-{
+if (isset($_POST['Location'])) {
$_SESSION['Items']->Location = $_POST['Location'];
}
-//--------------------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
function display_credit_items()
{
@@ -249,17 +224,27 @@ function display_credit_items()
end_row();
start_row();
- if (!isset($_POST['ref']))
- $_POST['ref'] = references::get_next(11);
+// if (!isset($_POST['ref']))
+// $_POST['ref'] = references::get_next(11);
- ref_cells(_("Reference"), 'ref', null, "class='tableheader2'");
+ if ($_SESSION['Items']->trans_no==0) {
+ ref_cells(_("Reference"), 'ref', '', $_SESSION['Items']->reference, "class='tableheader2'");
+ } else {
+ label_cells(_("Reference"), $_SESSION['Items']->reference, "class='tableheader2'");
+ }
+// label_cells(_("Crediting Invoice"), get_customer_trans_view_str(10, $_SESSION['InvoiceToCredit']), "class='tableheader2'");
+ label_cells(_("Crediting Invoice"), get_customer_trans_view_str(10, array_keys($_SESSION['Items']->src_docs)), "class='tableheader2'");
- label_cells(_("Crediting Invoice"), get_customer_trans_view_str(10, $_SESSION['InvoiceToCredit']), "class='tableheader2'");
+ if (!isset($_POST['ShipperID'])) {
+ $_POST['ShipperID'] = $_SESSION['Items']->ship_via;
+ }
+ label_cell(_("Shipping Company"), "class='tableheader2'");
+ shippers_list_cells(null, 'ShipperID', $_POST['ShipperID']);
+// if (!isset($_POST['sales_type_id']))
+// $_POST['sales_type_id'] = $_SESSION['Items']->sales_type;
+// label_cell(_("Sales Type"), "class='tableheader2'");
+// sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']);
- if (!isset($_POST['tax_group_id']))
- $_POST['tax_group_id'] = $_SESSION['Items']->tax_group_id;
- label_cell(_("Tax Group"), "class='tableheader2'");
- tax_groups_list_cells(null, 'tax_group_id', $_POST['tax_group_id'], false, null, true);
end_row();
end_table();
@@ -267,9 +252,9 @@ function display_credit_items()
start_table("$table_style width=100%");
- label_row(_("Invoice Date"), $_SESSION['Items']->delivery_date, "class='tableheader2'");
+ label_row(_("Invoice Date"), $_SESSION['Items']->src_date, "class='tableheader2'");
- date_row(_("Credit Note Date"), 'CreditDate', null, 0, 0, 0, "class='tableheader2'");
+ date_row(_("Credit Note Date"), 'CreditDate', '', null, 0, 0, 0, "class='tableheader2'");
end_table();
@@ -277,6 +262,7 @@ function display_credit_items()
end_table(1); // outer table
+ div_start('credit_items');
start_table("$table_style width=80%");
$th = array(_("Item Code"), _("Item Description"), _("Invoiced Quantity"), _("Units"),
_("Credit Quantity"), _("Price"), _("Discount %"), _("Total"));
@@ -284,110 +270,107 @@ function display_credit_items()
$k = 0; //row colour counter
- foreach ($_SESSION['Items']->line_items as $ln_itm)
- {
-
- alt_table_row_color($k);
+ foreach ($_SESSION['Items']->line_items as $line_no=>$ln_itm) {
+ if ($ln_itm->quantity==$ln_itm->qty_done) {
+ continue; // this line was fully credited
+ }
+ alt_table_row_color($k);
- $line_total =($ln_itm->qty_dispatched * $ln_itm->price * (1 - $ln_itm->discount_percent));
+ // view_stock_status_cell($ln_itm->stock_id); alternative view
label_cell($ln_itm->stock_id);
- text_cells(null, $ln_itm->stock_id . "Desc", $ln_itm->item_description, 30, 50);
- qty_cell($ln_itm->quantity);
- label_cell($ln_itm->units);
- text_cells(null, $ln_itm->stock_id, $ln_itm->qty_dispatched, 13, 15);
+ text_cells(null, 'Line'.$line_no.'Desc', $ln_itm->item_description, 30, 50);
+ $dec = get_qty_dec($ln_itm->stock_id);
+ qty_cell($ln_itm->quantity, false, $dec);
+ label_cell($ln_itm->units);
+ amount_cells(null, 'Line'.$line_no, number_format2($ln_itm->qty_dispatched, $dec),
+ null, null, $dec);
+ $line_total =($ln_itm->qty_dispatched * $ln_itm->price * (1 - $ln_itm->discount_percent));
amount_cell($ln_itm->price);
- amount_cell($ln_itm->discount_percent*100);
+ percent_cell($ln_itm->discount_percent*100);
amount_cell($line_total);
end_row();
}
- if (!isset($_POST['ChargeFreightCost']) || ($_POST['ChargeFreightCost'] == ""))
- {
- $_POST['ChargeFreightCost'] = $_SESSION['Items']->freight_cost;
+ if (!check_num('ChargeFreightCost')) {
+ $_POST['ChargeFreightCost'] = price_format($_SESSION['Items']->freight_cost);
}
+
start_row();
label_cell(_("Credit Shipping Cost"), "colspan=7 align=right");
- text_cells(null, "ChargeFreightCost", $_POST['ChargeFreightCost'], 6, 6);
+ amount_cells_ex(null, "ChargeFreightCost", 6, 8, $_POST['ChargeFreightCost']);
end_row();
$inv_items_total = $_SESSION['Items']->get_items_total_dispatch();
- $display_sub_total = number_format2($inv_items_total + $_POST['ChargeFreightCost'],user_price_dec());
+ $display_sub_total = price_format($inv_items_total + input_num($_POST['ChargeFreightCost']));
label_row(_("Sub-total"), $display_sub_total, "colspan=7 align=right", "align=right");
- $taxes = $_SESSION['Items']->get_taxes($_POST['tax_group_id'], $_POST['ChargeFreightCost']);
+ $taxes = $_SESSION['Items']->get_taxes(input_num($_POST['ChargeFreightCost']));
- $tax_total = display_edit_tax_items($taxes, 7);
+ $tax_total = display_edit_tax_items($taxes, 7, $_SESSION['Items']->tax_included);
- $display_total = number_format2(($inv_items_total + $_POST['ChargeFreightCost'] + $tax_total), user_price_dec());
+ $display_total = price_format(($inv_items_total + input_num('ChargeFreightCost') + $tax_total));
label_row(_("Credit Note Total"), $display_total, "colspan=7 align=right", "align=right");
end_table();
+ div_end();
}
-//--------------------------------------------------------------------------------------
-
+//-----------------------------------------------------------------------------
function display_credit_options()
{
- global $table_style2;
-
- echo "
";
- start_table($table_style2);
+ global $table_style2, $Ajax;
+ echo "
";
- echo "