|
@@ -1,66 +1,139 @@
|
|
|
angular.module('odoo')
|
|
|
|
|
|
-/**
|
|
|
- * -----------------------------------------------------------------------------
|
|
|
- * Description: Local storage manager for customers data
|
|
|
- * -----------------------------------------------------------------------------
|
|
|
- */
|
|
|
-.factory('customersStorageFactory', function () {
|
|
|
+ /**
|
|
|
+ * -----------------------------------------------------------------------------
|
|
|
+ * Description: Local storage manager for customers data
|
|
|
+ * -----------------------------------------------------------------------------
|
|
|
+ */
|
|
|
+ .factory('customersStorageFactory', function () {
|
|
|
|
|
|
- // Save customer data to local storage
|
|
|
- var save = function (customer, success, error) {
|
|
|
- var sql = '';
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var save = function (data, success, error) {
|
|
|
+ var query = null;
|
|
|
|
|
|
- if (customer.id) {
|
|
|
- sql = `UPDATE partner SET remote_id = ${ customer.remote_id ? customer.remote_id : 0 }, modified = 1, modifiedDate = CURRENT_TIMESTAMP, name = ${ customer.name ? '"' + customer.name + '"' : null }, city = ${ customer.city ? '"' + customer.city + '"' : null }, mobile = ${ customer.mobile ? '"' + customer.mobile + '"' : null }, phone = ${ customer.phone ? '"' + customer.phone + '"' : null }, fax = ${ customer.fax ? '"' + customer.fax + '"' : null }, email = ${ customer.email ? '"' + customer.email + '"' : null }, street = ${ customer.street ? '"' + customer.street + '"' : null }, street2 = ${ customer.street2 ? '"' + customer.street2 + '"' : null }, image_medium = ${ customer.image_medium ? '"' + customer.image_medium + '"' : null }, image_small = ${ customer.image_small ? '"' + customer.image_small + '"' : null }, comment = ${ customer.comment ? '"' + customer.comment + '"' : null }, customer = ${ customer.customer ? customer.customer : 1 }, employee = ${ customer.employee ? customer.employee : 0 }, is_company = ${ customer.is_company ? customer.is_company : 0 }, debit = ${ customer.debit ? customer.debit : 0 }, debit_limit = ${ customer.debit_limit ? customer.debit_limit : 0 }, opportunity_count = ${ customer.opportunity_count ? customer.opportunity_count : 0 }, contracts_count = ${ customer.contracts_count ? customer.contracts_count : 0 }, journal_item_count = ${ customer.journal_item_count ? customer.journal_item_count : 0 }, meeting_count = ${ customer.meeting_count ? customer.meeting_count : 0 }, phonecall_count = ${ customer.phonecall_count ? customer.phonecall_count : 0 }, sale_order_count = ${ customer.sale_order_count ? customer.sale_order_count : 0 }, total_invoiced = ${ customer.total_invoiced ? customer.total_invoiced : 0 } WHERE id = ${ customer.id }`;
|
|
|
- } else {
|
|
|
- sql = `INSERT INTO partner(remote_id, name, city, mobile, phone, fax, email, street, street2, image_medium, image_small, comment, customer, employee, is_company, debit, debit_limit, opportunity_count, contracts_count, journal_item_count, meeting_count, phonecall_count, sale_order_count, total_invoiced) VALUES (${ customer.remote_id ? customer.remote_id : 0 }, ${ customer.name ? '"' + customer.name + '"' : null }, ${ customer.city ? '"' + customer.city + '"' : null }, ${ customer.mobile ? '"' + customer.mobile + '"' : null }, ${ customer.phone ? '"' + customer.phone + '"' : null }, ${ customer.fax ? '"' + customer.fax + '"' : null }, ${ customer.email ? '"' + customer.email + '"' : null }, ${ customer.street ? '"' + customer.street + '"' : null }, ${ customer.street2 ? '"' + customer.street2 + '"' : null }, ${ customer.image_medium ? '"' + customer.image_medium + '"' : null }, ${ customer.image_small ? '"' + customer.image_small + '"' : null }, ${ customer.comment ? '"' + customer.comment + '"' : null }, 1, 0, 0, ${ customer.debit ? customer.debit : 0 }, ${ customer.debit_limit ? customer.debit_limit : 0 }, ${ customer.opportunity_count ? customer.opportunity_count : 0 }, ${ customer.contracts_count ? customer.contracts_count : 0 }, ${ customer.journal_item_count ? customer.journal_item_count : 0 }, ${ customer.meeting_count ? customer.meeting_count : 0 }, ${ customer.phonecall_count ? customer.phonecall_count : 0 }, ${ customer.sale_order_count ? customer.sale_order_count : 0 }, ${ customer.total_invoiced ? customer.total_invoiced : 0 })`;
|
|
|
- }
|
|
|
+ if (data.id) {
|
|
|
+ query = squel.update()
|
|
|
+ .table('partner')
|
|
|
+ .set('remote_id', data.remote_id)
|
|
|
+ .set('modified', 1)
|
|
|
+ .set('modifiedDate', 'CURRENT_TIMESTAMP', { dontQuote: true })
|
|
|
+ .set('name', data.name)
|
|
|
+ .set('city', data.city)
|
|
|
+ .set('mobile', data.mobile)
|
|
|
+ .set('phone', data.phone)
|
|
|
+ .set('fax', data.fax)
|
|
|
+ .set('email', data.email)
|
|
|
+ .set('street', data.street)
|
|
|
+ .set('street2', data.street2)
|
|
|
+ .set('image_medium', data.image_medium)
|
|
|
+ .set('image_small', data.image_small)
|
|
|
+ .set('comment', data.comment)
|
|
|
+ .set('customer', data.customer)
|
|
|
+ .set('employee', data.employee)
|
|
|
+ .set('is_company', data.is_company)
|
|
|
+ .set('debit', data.debit)
|
|
|
+ .set('debit_limit', data.debit_limit)
|
|
|
+ .set('opportunity_count', data.opportunity_count)
|
|
|
+ .set('contracts_count', data.contracts_count)
|
|
|
+ .set('journal_item_count', data.journal_item_count)
|
|
|
+ .set('meeting_count', data.meeting_count)
|
|
|
+ .set('phonecall_count', data.phonecall_count)
|
|
|
+ .set('sale_order_count', data.sale_order_count)
|
|
|
+ .set('total_invoiced', data.total_invoiced)
|
|
|
+ .where('id', data.id);
|
|
|
+ } else {
|
|
|
+ query = squel.insert()
|
|
|
+ .into('partner')
|
|
|
+ .set('remote_id', data.remote_id)
|
|
|
+ .set('modified', 0)
|
|
|
+ .set('modifiedDate', 'CURRENT_TIMESTAMP', { dontQuote: true })
|
|
|
+ .set('name', data.name)
|
|
|
+ .set('city', data.city)
|
|
|
+ .set('mobile', data.mobile)
|
|
|
+ .set('phone', data.phone)
|
|
|
+ .set('fax', data.fax)
|
|
|
+ .set('email', data.email)
|
|
|
+ .set('street', data.street)
|
|
|
+ .set('street2', data.street2)
|
|
|
+ .set('image_medium', data.image_medium)
|
|
|
+ .set('image_small', data.image_small)
|
|
|
+ .set('comment', data.comment)
|
|
|
+ .set('customer', data.customer)
|
|
|
+ .set('employee', data.employee)
|
|
|
+ .set('is_company', data.is_company)
|
|
|
+ .set('debit', data.debit)
|
|
|
+ .set('debit_limit', data.debit_limit)
|
|
|
+ .set('opportunity_count', data.opportunity_count)
|
|
|
+ .set('contracts_count', data.contracts_count)
|
|
|
+ .set('journal_item_count', data.journal_item_count)
|
|
|
+ .set('meeting_count', data.meeting_count)
|
|
|
+ .set('phonecall_count', data.phonecall_count)
|
|
|
+ .set('sale_order_count', data.sale_order_count)
|
|
|
+ .set('total_invoiced', data.total_invoiced);
|
|
|
+ }
|
|
|
|
|
|
- db.executeSql(sql, [], function(result) {
|
|
|
- success(sql.startsWith('INSERT') ? result.insertId : customer.id);
|
|
|
- }, function(err) {
|
|
|
- error(err);
|
|
|
- });
|
|
|
- };
|
|
|
+ query = query.toParam();
|
|
|
|
|
|
- // Delete customer from local storage
|
|
|
- var remove = function (customer, success, error) {
|
|
|
- if (!customer.id) {
|
|
|
- error('Customer cannot delete without provide an id');
|
|
|
- }
|
|
|
+ db.executeSql(query.text, query.values, function (result) {
|
|
|
+ success(query.text.startsWith('INSERT') ? result.insertId : customer.id);
|
|
|
+ }, function (err) {
|
|
|
+ error(err);
|
|
|
+ });
|
|
|
+ };
|
|
|
|
|
|
- var sql = '';
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var remove = function (data, success, error) {
|
|
|
+ if (!data.id) {
|
|
|
+ error('Customer cannot delete without provide an id');
|
|
|
+ }
|
|
|
|
|
|
- if (customer.remote_id) {
|
|
|
- sql = `UPDATE partner SET modified = 2 WHERE id = ${ customer.id }`;
|
|
|
- } else {
|
|
|
- sql = `DELETE FROM partner WHERE id = ${ customer.id }`;
|
|
|
- }
|
|
|
+ var query = null;
|
|
|
|
|
|
- console.log(sql);
|
|
|
+ if (data.remote_id) {
|
|
|
+ query = squel.update()
|
|
|
+ .table('partner')
|
|
|
+ .set('modified', 2)
|
|
|
+ .where('id', data.id)
|
|
|
+ .toParam();
|
|
|
+ } else {
|
|
|
+ query = squel.delete()
|
|
|
+ .from('partner')
|
|
|
+ .where('id', data.id)
|
|
|
+ .toParam();
|
|
|
+ }
|
|
|
|
|
|
- db.executeSql(sql, [], function(result) {
|
|
|
- success(result.rowsAffected);
|
|
|
- }, function(err) {
|
|
|
- error(err);
|
|
|
- });
|
|
|
- };
|
|
|
+ query = query.toParam();
|
|
|
|
|
|
- // Delete all customers from local storage
|
|
|
- var removeAll = function (success, error) {
|
|
|
- var sql = 'DELETE FROM partner WHERE customer = 1';
|
|
|
+ db.executeSql(query.text, query.values, function (result) {
|
|
|
+ success(result.rowsAffected);
|
|
|
+ }, function (err) {
|
|
|
+ error(err);
|
|
|
+ });
|
|
|
+ };
|
|
|
|
|
|
- db.executeSql(sql, [], function(result) {
|
|
|
- success(result.rowsAffected);
|
|
|
- }, function(err) {
|
|
|
- error(err);
|
|
|
- });
|
|
|
- };
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ var removeAll = function (success, error) {
|
|
|
+ var query = squel.delete()
|
|
|
+ .from('partner')
|
|
|
+ .where('customer', 1)
|
|
|
+ .toParam();
|
|
|
|
|
|
- return {
|
|
|
- save: save,
|
|
|
- remove: remove,
|
|
|
- removeAll: removeAll
|
|
|
- }
|
|
|
-});
|
|
|
+ db.executeSql(query.text, query.values, function (result) {
|
|
|
+ success(result.rowsAffected);
|
|
|
+ }, function (err) {
|
|
|
+ error(err);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ return {
|
|
|
+ save: save,
|
|
|
+ remove: remove,
|
|
|
+ removeAll: removeAll
|
|
|
+ }
|
|
|
+ });
|