Added company switch for placing company logo on certain views.
[fa-stable.git] / purchasing / view / view_po.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_SUPPTRANSVIEW';
13 $path_to_root = "../..";
14 include($path_to_root . "/purchasing/includes/po_class.inc");
15
16 include($path_to_root . "/includes/session.inc");
17 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
18
19 $js = "";
20 if ($SysPrefs->use_popup_windows)
21         $js .= get_js_open_window(900, 500);
22 page(_($help_context = "View Purchase Order"), true, false, "", $js);
23
24
25 if (!isset($_GET['trans_no']))
26 {
27         die ("<br>" . _("This page must be called with a purchase order number to review."));
28 }
29
30 if (!empty($SysPrefs->prefs['company_logo_on_views']))
31         company_logo_on_view();
32
33 display_heading(_("Purchase Order") . " #" . $_GET['trans_no']);
34
35 $purchase_order = new purch_order;
36
37 read_po($_GET['trans_no'], $purchase_order);
38 echo "<br>";
39 display_po_summary($purchase_order, true);
40
41 start_table(TABLESTYLE, "width='90%'", 6);
42 echo "<tr><td valign=top>"; // outer table
43
44 display_heading2(_("Line Details"));
45
46 start_table(TABLESTYLE, "width='100%'");
47
48 $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), _("Price"),
49         _("Requested By"), _("Line Total"), _("Quantity Received"), _("Quantity Invoiced"));
50 table_header($th);
51 $total = $k = 0;
52 $overdue_items = false;
53
54 foreach ($purchase_order->line_items as $stock_item)
55 {
56
57         $line_total = $stock_item->quantity * $stock_item->price;
58
59         // if overdue and outstanding quantities, then highlight as so
60         if (($stock_item->quantity - $stock_item->qty_received > 0)     &&
61                 date1_greater_date2(Today(), $stock_item->req_del_date))
62         {
63         start_row("class='overduebg'");
64         $overdue_items = true;
65         }
66         else
67         {
68                 alt_table_row_color($k);
69         }
70
71         label_cell($stock_item->stock_id);
72         label_cell($stock_item->item_description);
73         $dec = get_qty_dec($stock_item->stock_id);
74         qty_cell($stock_item->quantity, false, $dec);
75         label_cell($stock_item->units);
76         amount_decimal_cell($stock_item->price);
77         label_cell($stock_item->req_del_date);
78         amount_cell($line_total);
79         qty_cell($stock_item->qty_received, false, $dec);
80         qty_cell($stock_item->qty_inv, false, $dec);
81         end_row();
82
83         $total += $line_total;
84 }
85
86 $display_sub_tot = number_format2($total,user_price_dec());
87 label_row(_("Sub Total"), $display_sub_tot,
88         "align=right colspan=6", "nowrap align=right",2);
89
90 $taxes = $purchase_order->get_taxes();
91 $tax_total = display_edit_tax_items($taxes, 6, $purchase_order->tax_included,2);
92
93 $display_total = price_format(($total + $tax_total));
94
95 start_row();
96 label_cells(_("Amount Total"), $display_total, "colspan=6 align='right'","align='right'");
97 label_cell('', "colspan=2");
98 end_row();
99
100 end_table();
101
102 if ($overdue_items)
103         display_note(_("Marked items are overdue."), 0, 0, "class='overduefg'");
104
105 //----------------------------------------------------------------------------------------------------
106
107 $k = 0;
108
109 $grns_result = get_po_grns($_GET['trans_no']);
110
111 if (db_num_rows($grns_result) > 0)
112 {
113
114     echo "</td><td valign=top>"; // outer table
115
116     display_heading2(_("Deliveries"));
117     start_table(TABLESTYLE);
118     $th = array(_("#"), _("Reference"), _("Delivered On"));
119     table_header($th);
120     while ($myrow = db_fetch($grns_result))
121     {
122                 alt_table_row_color($k);
123
124         label_cell(get_trans_view_str(ST_SUPPRECEIVE,$myrow["id"]));
125         label_cell($myrow["reference"]);
126         label_cell(sql2date($myrow["delivery_date"]));
127         end_row();
128     }
129     end_table();
130 }
131
132 $invoice_result = get_po_invoices_credits($_GET['trans_no']);
133
134 $k = 0;
135
136 if (db_num_rows($invoice_result) > 0)
137 {
138
139     echo "</td><td valign=top>"; // outer table
140
141     display_heading2(_("Invoices/Credits"));
142     start_table(TABLESTYLE);
143     $th = array(_("#"), _("Date"), _("Total"));
144     table_header($th);
145     while ($myrow = db_fetch($invoice_result))
146     {
147         alt_table_row_color($k);
148
149         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
150         label_cell(sql2date($myrow["tran_date"]));
151         amount_cell($myrow["Total"]);
152         end_row();
153     }
154     end_table();
155 }
156
157 echo "</td></tr>";
158
159 end_table(1); // outer table
160
161 display_allocations_to(PT_SUPPLIER, $purchase_order->supplier_id, ST_PURCHORDER, $purchase_order->order_no, $total + $tax_total);
162
163 //----------------------------------------------------------------------------------------------------
164
165 end_page(true, false, false, ST_PURCHORDER, $_GET['trans_no']);
166