/[drupal]/contributions/modules/invoice/invoice.install
ViewVC logotype

Contents of /contributions/modules/invoice/invoice.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Sat Dec 13 14:03:32 2008 UTC (11 months, 2 weeks ago) by pvogelaar
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
File MIME type: text/x-php
* Fixed bug: "Invoice items : Unit Cost incl VAT is wrong whent you use a VAT less of 10%" => http://drupal.org/node/345800
* Added a TODO: Possibility to link an invoice to a site user + page for that user to view his invoices => http://drupal.org/node/346516
  - With a extra option to also send the invoice by email (if no site user is selected the customer email field that is not implemented yet
    will be choosen, if both are empty an error will be thrown if this checkbox is still checked. => http://drupal.org/node/346005
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Invoice module
7 *
8 * This module was developed by Platina Designs, http://www.platinadesigns.nl
9 *
10 * @author Pieter Vogelaar <ps.vogelaar@platinadesigns.nl>
11 * @date Change 11 nov 2008: Added and tested invoice_update_1() function, works 100% correct.
12 */
13
14 /**
15 * Implementation of hook_install()
16 */
17 function invoice_install() {
18
19 drupal_install_schema('invoice');
20 variable_set('invoice_locale', 'en_US.utf8');
21 variable_set('invoice_date_format', 'm/d/Y');
22 variable_set('invoice_pay_limit', '14'); // Pay limit in days
23 variable_set('invoice_vat', '19'); // VAT percentage
24 variable_set('invoice_invoice_number_zerofill', 4);
25 variable_set('invoice_invoice_number_prefix', '%Y');
26 variable_set('invoice_default_template', 'default');
27 variable_set('invoice_supplier_company_name', 'My company');
28
29 /**
30 * Makes sure that node promote flag is off
31 *
32 * On ?q=admin/content/node-type/invoice there is a checkbox in the workflow fieldset that is
33 * called "Promoted to front page", if this is turned on invoices will be displayed at ?q=node
34 * global node overview. Because invoices are private, I guess this must always be disabled
35 * for anyone.
36 */
37 $node_options = variable_get('node_options_invoice', array());
38 if (in_array('promote', $node_options)) {
39 foreach ($node_options as $key => $option) {
40 if ($option == 'promote') {
41 unset($node_options[$key]);
42 }
43 }
44 }
45
46 $node_options[] = 'status';
47 variable_set('node_options_invoice', $node_options);
48 }
49
50 /**
51 * Implementation of hook_uninstall()
52 */
53 function invoice_uninstall() {
54 // Drop all invoice tables
55 // drupal_uninstall_schema('invoice'); // If some admin get hacked, it's probably not desirable that all invoices can be deleted in a few steps
56 }
57
58 /**
59 * Implementation of hook_update_N()
60 *
61 * @return array Array with query results
62 */
63 function invoice_update_1() {
64 $ret = array(); // Array to which query results will be added.
65
66 // Update invoice_customers table
67 db_add_index($ret, 'invoice_customers', 'cid', array('cid'));
68 db_drop_primary_key($ret, 'invoice_customers');
69 db_change_field($ret, 'invoice_customers', 'cid', 'cid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('cid')));
70 db_drop_index($ret, 'invoice_customers', 'cid');
71
72 db_change_field($ret, 'invoice_customers', 'customer_number', 'customer_number', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
73 db_change_field($ret, 'invoice_customers', 'company_name', 'company_name', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
74 db_change_field($ret, 'invoice_customers', 'firstname', 'firstname', array('type' => 'varchar', 'length' => 50, 'not null' => FALSE));
75 db_change_field($ret, 'invoice_customers', 'lastname', 'lastname', array('type' => 'varchar', 'length' => 50, 'not null' => FALSE));
76 db_change_field($ret, 'invoice_customers', 'street', 'street', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
77 db_change_field($ret, 'invoice_customers', 'building_number', 'building_number', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
78 db_change_field($ret, 'invoice_customers', 'zipcode', 'zipcode', array('type' => 'varchar', 'length' => 10, 'not null' => FALSE));
79 db_change_field($ret, 'invoice_customers', 'city', 'city', array('type' => 'varchar', 'length' => 50, 'not null' => FALSE));
80 db_change_field($ret, 'invoice_customers', 'country', 'country', array('type' => 'varchar', 'length' => 50, 'not null' => FALSE));
81 db_change_field($ret, 'invoice_customers', 'coc_number', 'coc_number', array('type' => 'varchar', 'length' => 25, 'not null' => FALSE));
82 db_change_field($ret, 'invoice_customers', 'vat_number', 'vat_number', array('type' => 'varchar', 'length' => 25, 'not null' => FALSE));
83 db_change_field($ret, 'invoice_customers', 'description', 'description', array('type' => 'text', 'not null' => FALSE));
84
85 db_drop_index($ret, 'invoice_customers', 'invoice_id');
86 db_change_field($ret, 'invoice_customers', 'invoice_id', 'invoice_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
87 db_add_index($ret, 'invoice_customers', 'invoice_id', array('invoice_id'));
88
89 db_add_index($ret, 'invoice_customers', 'customer_number', array('customer_number'));
90
91 // Update invoice_invoices table
92 db_add_index($ret, 'invoice_invoices', 'iid', array('iid'));
93 db_drop_primary_key($ret, 'invoice_invoices');
94 db_change_field($ret, 'invoice_invoices', 'iid', 'iid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('iid')));
95 db_drop_index($ret, 'invoice_invoices', 'iid');
96
97 db_change_field($ret, 'invoice_invoices', 'description', 'description', array('type' => 'text', 'not null' => FALSE));
98
99 db_change_field($ret, 'invoice_invoices', 'tid', 'tid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
100 db_add_index($ret, 'invoice_invoices', 'tid', array('tid'));
101
102 db_change_field($ret, 'invoice_invoices', 'pay_limit', 'pay_limit', array('type' => 'int', 'size' => 'small', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
103 db_change_field($ret, 'invoice_invoices', 'pay_status', 'pay_status', array('type' => 'varchar', 'length' => 10, 'not null' => TRUE, 'default' => 'unpaid'));
104 db_drop_field($ret, 'invoice_invoices', 'depricated_created');
105
106 db_drop_index($ret, 'invoice_invoices', 'nid');
107 db_change_field($ret, 'invoice_invoices', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
108 db_add_unique_key($ret, 'invoice_invoices', 'nid', array('nid'));
109
110 db_drop_index($ret, 'invoice_invoices', 'uid');
111 db_change_field($ret, 'invoice_invoices', 'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE));
112 db_add_index($ret, 'invoice_invoices', 'uid', array('uid'));
113
114 // Update invoice_items table
115 db_add_index($ret, 'invoice_items', 'iid', array('iid'));
116 db_drop_primary_key($ret, 'invoice_items');
117 db_change_field($ret, 'invoice_items', 'iid', 'iid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('iid')));
118 db_drop_index($ret, 'invoice_items', 'iid');
119
120 db_change_field($ret, 'invoice_items', 'description', 'description', array('type' => 'text', 'size' => 'medium', 'not null' => FALSE));
121 db_change_field($ret, 'invoice_items', 'unitcost', 'unitcost', array('type' => 'float', 'size' => 'big', 'not null' => TRUE, 'default' => 0));
122
123 db_change_field($ret, 'invoice_items', 'vat', 'vat', array('type' => 'float', 'size' => 'big', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
124 db_change_field($ret, 'invoice_items', 'weight', 'weight', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
125
126 db_drop_index($ret, 'invoice_items', 'uid');
127 db_change_field($ret, 'invoice_items', 'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE));
128 db_add_index($ret, 'invoice_items', 'uid', array('uid'));
129
130 db_change_field($ret, 'invoice_items', 'created', 'created', array('type' => 'datetime', 'not null' => TRUE));
131
132 db_drop_index($ret, 'invoice_items', 'invoice_id');
133 db_change_field($ret, 'invoice_items', 'invoice_id', 'invoice_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
134 db_add_index($ret, 'invoice_items', 'invoice_id', array('invoice_id'));
135
136 // Update invoice_templates table
137 db_add_index($ret, 'invoice_templates', 'tid', array('tid'));
138 db_drop_primary_key($ret, 'invoice_templates');
139 db_change_field($ret, 'invoice_templates', 'tid', 'tid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('tid')));
140 db_drop_index($ret, 'invoice_templates', 'tid');
141
142 db_drop_unique_key($ret, 'invoice_templates', 'name');
143 db_change_field($ret, 'invoice_templates', 'name', 'name', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
144 db_add_unique_key($ret, 'invoice_templates', 'name', array('name'));
145
146 db_change_field($ret, 'invoice_templates', 'locale', 'locale', array('type' => 'varchar', 'length' => '25', 'not null' => FALSE));
147 db_change_field($ret, 'invoice_templates', 'date_format', 'date_format', array('type' => 'varchar', 'length' => 50, 'not null' => FALSE));
148 db_change_field($ret, 'invoice_templates', 'vat', 'vat', array('type' => 'float', 'size' => 'big', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
149 db_change_field($ret, 'invoice_templates', 'pay_limit', 'pay_limit', array('type' => 'int', 'size' => 'small', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
150 db_change_field($ret, 'invoice_templates', 'supplier_company_name', 'supplier_company_name', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
151 db_change_field($ret, 'invoice_templates', 'supplier_street', 'supplier_street', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
152 db_change_field($ret, 'invoice_templates', 'supplier_building_number', 'supplier_building_number', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
153 db_change_field($ret, 'invoice_templates', 'supplier_zipcode', 'supplier_zipcode', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
154 db_change_field($ret, 'invoice_templates', 'supplier_city', 'supplier_city', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
155 db_change_field($ret, 'invoice_templates', 'supplier_country', 'supplier_country', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
156 db_change_field($ret, 'invoice_templates', 'supplier_phone', 'supplier_phone', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
157 db_change_field($ret, 'invoice_templates', 'supplier_fax', 'supplier_fax', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
158 db_change_field($ret, 'invoice_templates', 'supplier_email', 'supplier_email', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
159 db_change_field($ret, 'invoice_templates', 'supplier_web', 'supplier_web', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
160 db_change_field($ret, 'invoice_templates', 'supplier_coc_number', 'supplier_coc_number', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
161 db_change_field($ret, 'invoice_templates', 'supplier_vat_number', 'supplier_vat_number', array('type' => 'varchar', 'length' => 100, 'not null' => FALSE));
162
163 return $ret; // Array with query results.
164 }
165
166 /**
167 * Implementation of hook_update_N()
168 *
169 * @return array Array with query results
170 */
171 function invoice_update_2() {
172 $ret = array(); // Array to which query results will be added.
173
174 db_add_field($ret, 'invoice_templates', 'display_column_vat', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
175 db_add_field($ret, 'invoice_templates', 'display_column_exunitcost', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1));
176 db_add_field($ret, 'invoice_templates', 'display_column_incunitcost', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1));
177 db_add_field($ret, 'invoice_templates', 'display_column_extotal', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1));
178 db_add_field($ret, 'invoice_templates', 'display_column_inctotal', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1));
179
180 return $ret; // Array with query results.
181 }
182
183 /**
184 * Implementation of hook_update_N()
185 *
186 * @return array Array with query results
187 */
188 function invoice_update_3() {
189 $ret = array(); // Array to which query results will be added.
190
191 if (is_null(variable_get('invoice_invoice_number_zerofill', NULL))) {
192 variable_set('invoice_invoice_number_zerofill', 4);
193 }
194
195 if (is_null(variable_get('invoice_invoice_number_prefix', NULL))) {
196 variable_set('invoice_invoice_number_prefix', '%Y');
197 }
198
199 db_add_field($ret, 'invoice_invoices', 'leading_zeros', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
200 db_add_field($ret, 'invoice_invoices', 'prefix', array('type' => 'varchar', 'length' => 50, 'not null' => FALSE));
201
202 return $ret; // Array with query results.
203 }
204
205 /**
206 * Implementation of hook_update_N()
207 *
208 * This update fixes a privacy issue
209 *
210 * @return array Array with query results
211 */
212 function invoice_update_4() {
213 /**
214 * Makes sure that node promote flag is off
215 *
216 * On ?q=admin/content/node-type/invoice there is a checkbox in the workflow fieldset that is
217 * called "Promoted to front page", if this is turned on invoices will be displayed at ?q=node
218 * global node overview. Because invoices are private, I guess this must always be disabled
219 * for anyone.
220 */
221 $node_options = variable_get('node_options_invoice', array());
222 if (in_array('promote', $node_options)) {
223 foreach ($node_options as $key => $option) {
224 if ($option == 'promote') {
225 unset($node_options[$key]);
226 }
227 }
228 }
229 variable_set('node_options_invoice', $node_options);
230
231 db_query("UPDATE {node} SET promote=0 WHERE type='invoice'");
232
233 return array();
234 }
235
236 /**
237 * Implementation of hook_schema()
238 *
239 * @return array
240 */
241 function invoice_schema() {
242
243 $schema['invoice_customers'] = array(
244 'fields' => array(
245 'cid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
246 'customer_number' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
247 'company_name' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
248 'firstname' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
249 'lastname' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
250 'street' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
251 'building_number' => array('type' => 'varchar', 'length' => 15, 'not null' => FALSE),
252 'zipcode' => array('type' => 'varchar', 'length' => 25, 'not null' => FALSE),
253 'city' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
254 'country' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
255 'coc_number' => array('type' => 'varchar', 'length' => 25, 'not null' => FALSE),
256 'vat_number' => array('type' => 'varchar', 'length' => 25, 'not null' => FALSE),
257 'description' => array('type' => 'text', 'not null' => FALSE),
258 'invoice_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
259 ),
260 'primary key' => array('cid'),
261 'unique keys' => array(),
262 'indexes' => array(
263 'invoice_id' => array('invoice_id'),
264 'customer_number' => array('customer_number'),
265 ),
266 );
267
268 $schema['invoice_invoices'] = array(
269 'fields' => array(
270 'iid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
271 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
272 'leading_zeros' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
273 'prefix' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
274 'description' => array('type' => 'text', 'not null' => FALSE),
275 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
276 'pay_limit' => array('type' => 'int', 'size' => 'small', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
277 'pay_status' => array('type' => 'varchar', 'length' => 10, 'not null' => TRUE, 'default' => 'unpaid'),
278 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
279 ),
280 'primary key' => array('iid'),
281 'unique keys' => array(
282 'nid' => array('nid'),
283 ),
284 'indexes' => array(
285 'tid' => array('tid'),
286 'uid' => array('uid'),
287 ),
288 );
289
290 $schema['invoice_items'] = array(
291 'fields' => array(
292 'iid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
293 'description' => array('type' => 'text', 'size' => 'medium', 'not null' => FALSE),
294 'quantity' => array('type' => 'float', 'size' => 'big', 'not null' => TRUE, 'default' => 0),
295 'unitcost' => array('type' => 'float', 'size' => 'big', 'not null' => TRUE, 'default' => 0),
296 'vat' => array('type' => 'float', 'size' => 'big', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
297 'weight' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
298 'invoice_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
299 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
300 'created' => array('type' => 'datetime', 'not null' => TRUE),
301 ),
302 'primary key' => array('iid'),
303 'unique keys' => array(),
304 'indexes' => array(
305 'invoice_id' => array('invoice_id'),
306 'uid' => array('uid'),
307 ),
308 );
309
310 $schema['invoice_templates'] = array(
311 'fields' => array(
312 'tid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
313 'name' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
314 'locale' => array('type' => 'varchar', 'length' => '25', 'not null' => FALSE),
315 'date_format' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
316 'vat' => array('type' => 'float', 'size' => 'big', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
317 'pay_limit' => array('type' => 'int', 'size' => 'small', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
318 'supplier_company_name' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
319 'supplier_street' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
320 'supplier_building_number' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
321 'supplier_zipcode' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
322 'supplier_city' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
323 'supplier_country' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
324 'supplier_phone' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
325 'supplier_fax' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
326 'supplier_email' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
327 'supplier_web' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
328 'supplier_coc_number' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
329 'supplier_vat_number' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE),
330 'display_column_vat' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
331 'display_column_exunitcost' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1),
332 'display_column_incunitcost' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1),
333 'display_column_extotal' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1),
334 'display_column_inctotal' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1),
335 ),
336 'primary key' => array('tid'),
337 'unique keys' => array(
338 'name' => array('name'),
339 ),
340 'indexes' => array(),
341 );
342
343 return $schema;
344 }

  ViewVC Help
Powered by ViewVC 1.1.2