5 include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
9 include_once($path_to_root . "/includes/session.inc");
11 include_once($path_to_root . "/includes/data_checks.inc");
13 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
14 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
16 if ($use_popup_windows)
17 $js .= get_js_open_window(900, 500);
19 $js .= get_js_date_picker();
20 page(_("Supplier Credit Note"), false, false, "", $js);
22 //----------------------------------------------------------------------------------------
24 check_db_has_suppliers(_("There are no suppliers defined in the system."));
26 //---------------------------------------------------------------------------------------------------------------
28 if (isset($_GET['AddedID']))
30 $invoice_no = $_GET['AddedID'];
35 display_notification_centered(_("Supplier credit note has been processed."));
36 display_note(get_trans_view_str($trans_type, $invoice_no, _("View this Credit Note")));
38 display_note(get_gl_view_str($trans_type, $invoice_no, _("View the GL Journal Entries for this Credit Note")), 1);
40 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Credit Note"), "New=1");
42 display_footer_exit();
45 //---------------------------------------------------------------------------------------------------
47 if (isset($_GET['New']))
49 if (isset( $_SESSION['supp_trans']))
51 unset ($_SESSION['supp_trans']->grn_items);
52 unset ($_SESSION['supp_trans']->gl_codes);
53 unset ($_SESSION['supp_trans']);
56 $_SESSION['supp_trans'] = new supp_trans;
57 $_SESSION['supp_trans']->is_invoice = false;
60 //---------------------------------------------------------------------------------------------------
64 global $total_grn_value, $total_gl_value;
66 if (!$_SESSION['supp_trans']->is_valid_trans_to_post())
68 display_error(_("The credit note cannot be processed because the there are no items or values on the invoice. Credit notes are expected to have a charge."));
73 if (!references::is_valid($_SESSION['supp_trans']->reference))
75 display_error(_("You must enter an credit note reference."));
76 set_focus('reference');
80 if (!is_new_reference($_SESSION['supp_trans']->reference, 21))
82 display_error(_("The entered reference is already in use."));
83 set_focus('reference');
87 if (!references::is_valid($_SESSION['supp_trans']->supp_reference))
89 display_error(_("You must enter a supplier's credit note reference."));
90 set_focus('supp_reference');
94 if (!is_date($_SESSION['supp_trans']->tran_date))
96 display_error(_("The credit note as entered cannot be processed because the date entered is not valid."));
97 set_focus('tran_date');
100 elseif (!is_date_in_fiscalyear($_SESSION['supp_trans']->tran_date))
102 display_error(_("The entered date is not in fiscal year."));
103 set_focus('tran_date');
106 if (!is_date( $_SESSION['supp_trans']->due_date))
108 display_error(_("The invoice as entered cannot be processed because the due date is in an incorrect format."));
109 set_focus('due_date');
113 if ($_SESSION['supp_trans']->ov_amount < ($total_gl_value + $total_grn_value))
115 display_error(_("The credit note total as entered is less than the sum of the the general ledger entires (if any) and the charges for goods received. There must be a mistake somewhere, the credit note as entered will not be processed."));
122 //---------------------------------------------------------------------------------------------------
124 function handle_commit_credit_note()
126 copy_to_trans($_SESSION['supp_trans']);
131 $invoice_no = add_supp_invoice($_SESSION['supp_trans']);
133 $_SESSION['supp_trans']->clear_items();
134 unset($_SESSION['supp_trans']);
136 meta_forward($_SERVER['PHP_SELF'], "AddedID=$invoice_no");
139 //--------------------------------------------------------------------------------------------------
141 if (isset($_POST['PostCreditNote']))
143 handle_commit_credit_note();
146 //--------------------------------------------------------------------------------------------------
148 start_form(false, true);
150 start_table("$table_style width=80%", 8);
151 echo "<tr><td valign=center>"; // outer table
155 invoice_header($_SESSION['supp_trans']);
156 if ($_POST['supplier_id']=='')
157 display_error('No supplier found for entered search text');
159 echo "</td></tr><tr><td valign=center>"; // outer table
161 $total_grn_value = display_grn_items($_SESSION['supp_trans']);
163 $total_gl_value = display_gl_items($_SESSION['supp_trans']);
165 echo "</td></tr><tr><td align=center colspan=2>"; // outer table
167 invoice_totals($_SESSION['supp_trans']);
171 end_table(1); // outer table
173 submit_center('PostCreditNote', _("Enter Credit Note"), true, '', true);