-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddedit.php
More file actions
140 lines (123 loc) · 5.06 KB
/
Copy pathaddedit.php
File metadata and controls
140 lines (123 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php /* INVOICES $Id: addedit.php,v 1.0 2004/03/24 02:47:22 mfinger Exp $ */
$invoice_id = intval( dPgetParam( $_GET, "invoice_id", 0 ) );
// check permissions for this record
$canEdit = !getDenyEdit( $m, $invoice_id );
if (!$canEdit) {
$AppUI->redirect( "m=public&a=access_denied" );
}
// get a list of permitted companies
require_once( $AppUI->getModuleClass ('companies' ) );
$row = new CCompany();
$companies = $row->getAllowedRecords( $AppUI->user_id, 'company_id,company_name', 'company_name' );
$companies = arrayMerge( array( '0'=>'Select Company' ), $companies );
// pull users
$sql = "SELECT user_id, CONCAT_WS(', ',user_last_name,user_first_name) FROM users ORDER BY user_last_name";
$users = db_loadHashList( $sql );
// load the record data
$row = new CInvoice();
if (!$row->load( $invoice_id ) && $invoice_id > 0) {
$AppUI->setMsg( 'Invoice' );
$AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
$AppUI->redirect();
} else if (count( $companies ) < 2 && $invoice_id == 0) {
$AppUI->setMsg( "noCompanies", UI_MSG_ERROR, true );
$AppUI->redirect();
}
// add in the existing company if for some reason it is dis-allowed
if ($invoice_id && !array_key_exists( $row->invoice_company, $companies )) {
$companies[$row->invoice_company] = db_loadResult(
"SELECT company_name FROM companies WHERE company_id=$row->invoice_company"
);
}
// format dates
$df = $AppUI->getPref('SHDATEFORMAT');
$invoice_date = new CDate( $row->invoice_date );
$invoice_due = new CDate( $row->invoice_due );
$invoice_due == $invoice_date ? $invoice_due->addDays(+30) : $invoice_due;
// setup the title block
$ttl = $invoice_id > 0 ? "Edit Invoice" : "New Invoice";
$titleBlock = new CTitleBlock( $ttl, 'applet3-48.png', $m, "$m.$a" );
$titleBlock->addCrumb( "?m=invoices", "invoices list" );
if ($invoice_id != 0)
$titleBlock->addCrumb( "?m=invoices&a=view&invoice_id=$invoice_id", "view this invoice" );
$titleBlock->show();
?>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo $AppUI->cfg['base_url'];?>/lib/calendar/calendar-dp.css" title="blue" />
<!-- import the calendar script -->
<script type="text/javascript" src="<?php echo $AppUI->cfg['base_url'];?>/lib/calendar/calendar.js"></script>
<!-- import the language module -->
<script type="text/javascript" src="<?php echo $AppUI->cfg['base_url'];?>/lib/calendar/lang/calendar-<?php echo $AppUI->user_locale; ?>.js"></script>
<script language="javascript">
function submitIt() {
var f = document.editFrm;
var msg = '';
if (f.invoice_company.options[f.invoice_company.selectedIndex].value < 1) {
msg += "\n<?php echo $AppUI->_('invoicesBadCompany');?>";
f.invoice_company.focus();
}
if (f.invoice_due.value < f.invoice_date.value) {
msg += "\n<?php echo $AppUI->_('invoicesBadEndDate1');?>";
}
if (msg.length < 1) {
f.submit();
} else {
alert(msg);
}
}
</script>
<table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
<form name="editFrm" action="./index.php?m=invoices" method="post">
<input type="hidden" name="dosql" value="do_invoice_aed" />
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id;?>" />
<tr>
<td width="50%" valign="top">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="right" nowrap="nowrap"><?php echo $AppUI->_('Company');?></td>
<td width="100%" nowrap="nowrap">
<?php
echo arraySelect( $companies, 'invoice_company', 'class="text" size="1"', $row->invoice_company );
?> *</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?php echo $AppUI->_('Invoice Date');?></td>
<td>
<input type="text" class="text" name="invoice_date" id="date1" value="<?php echo $invoice_date->format( '%Y-%m-%d' );?>" />
<a href="#" onClick="return showCalendar('date1', 'y-mm-dd');">
<img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
</a>
yyyy-mm-dd
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?php echo $AppUI->_('Due Date');?></td>
<td>
<input type="text" class="text" name="invoice_due" id="date2" value="<?php echo $invoice_due->format( '%Y-%m-%d');?>" />
<a href="#" onClick="return showCalendar('date2', 'y-mm-dd');">
<img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
</a>
yyyy-mm-dd
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?php echo $AppUI->_('Terms');?></td>
<td>
<input type="text" name="invoice_terms" value="<?php echo @$row->invoice_terms == null ? 'Net 30' : $row->invoice_terms;?>" size="40" maxlength="255" class="text" />
</td>
</tr>
</table>
</td>
<td width="50%" valign="top">
</td>
<tr>
<td>
<input class="button" type="button" name="cancel" value="<?php echo $AppUI->_('cancel');?>" onClick="javascript:if(confirm('Are you sure you want to cancel.')){location.href = './index.php?m=invoices';}" />
</td>
<td align="right">
<input class="button" type="button" name="btnFuseAction" value="<?php echo $AppUI->_('submit');?>" onClick="submitIt();" />
</td>
</tr>
</form>
</table>
* <?php echo $AppUI->_('requiredField');?>