Example #1
0
 public function __construct($sync = true)
 {
     $this->security_id = $_SESSION['admin_security'][SECURITY_ID_CONFIGURATION];
     require_once DIR_FS_MODULES . 'phreedom/functions/phreedom.php';
     foreach ($_POST as $key => $value) {
         $this->{$key} = $value;
     }
     $this->id = isset($_POST['sID']) ? $_POST['sID'] : $_GET['sID'];
     if ($sync) {
         xtra_field_sync_list($this->module, $this->db_table);
     }
 }
Example #2
0
 function update($module)
 {
     global $db, $messageStack;
     $error = false;
     if (MODULE_ASSETS_STATUS < 3.1) {
         $tab_map = array('0' => '0');
         if (db_table_exists(DB_PREFIX . 'assets_tabs')) {
             $result = $db->Execute("select * from " . DB_PREFIX . 'assets_tabs');
             while (!$result->EOF) {
                 $updateDB = $db->Execute("insert into " . TABLE_EXTRA_TABS . " set \n\t\t\t  module_id = 'assets',\n\t\t\t  tab_name = '" . $result->fields['category_name'] . "',\n\t\t\t  description = '" . $result->fields['category_description'] . "',\n\t\t\t  sort_order = '" . $result->fields['sort_order'] . "'");
                 $tab_map[$result->fields['category_id']] = db_insert_id();
                 $result->MoveNext();
             }
             $db->Execute("DROP TABLE " . DB_PREFIX . "assets_tabs");
         }
         if (db_table_exists(DB_PREFIX . 'assets_fields')) {
             $result = $db->Execute("select * from " . DB_PREFIX . 'assets_fields');
             while (!$result->EOF) {
                 $updateDB = $db->Execute("insert into " . TABLE_EXTRA_FIELDS . " set \n\t\t\t  module_id = 'assets',\n\t\t\t  tab_id = '" . $tab_map[$result->fields['category_id']] . "',\n\t\t\t  entry_type = '" . $result->fields['entry_type'] . "',\n\t\t\t  field_name = '" . $result->fields['field_name'] . "',\n\t\t\t  description = '" . $result->fields['description'] . "',\n\t\t\t  params = '" . $result->fields['params'] . "'");
                 $result->MoveNext();
             }
             $db->Execute("DROP TABLE " . DB_PREFIX . "assets_fields");
         }
         xtra_field_sync_list('assets', TABLE_ASSETS);
     }
     if (MODULE_ASSETS_STATUS < 3.3) {
         if (!db_field_exists(TABLE_ASSETS, 'attachments')) {
             $db->Execute("ALTER TABLE " . TABLE_ASSETS . " ADD attachments TEXT NOT NULL AFTER terminal_date");
         }
         require_once DIR_FS_MODULES . 'phreedom/functions/phreedom.php';
         xtra_field_sync_list('assets', TABLE_ASSETS);
     }
     if (!$error) {
         write_configure('MODULE_' . strtoupper($module) . '_STATUS', constant('MODULE_' . strtoupper($module) . '_VERSION'));
         $messageStack->add(sprintf(GEN_MODULE_UPDATE_SUCCESS, $module, constant('MODULE_' . strtoupper($module) . '_VERSION')), 'success');
     }
     return $error;
 }
Example #3
0
 function update($module)
 {
     global $db, $messageStack;
     $error = false;
     if (MODULE_CONTACTS_STATUS < 3.3) {
         $db->Execute("ALTER TABLE " . TABLE_CONTACTS . " CHANGE short_name short_name VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''");
         if (!db_table_exists(TABLE_CONTACTS_LOG)) {
             foreach ($this->tables as $table => $sql) {
                 if ($table == TABLE_CONTACTS_LOG) {
                     admin_install_tables(array($table => $sql));
                 }
             }
         }
         if (db_table_exists(DB_PREFIX . 'contacts_extra_fields')) {
             // first create a new tab
             if (!defined('SETUP_TITLE_EXTRA_FIELDS')) {
                 define('SETUP_TITLE_EXTRA_FIELDS', 'New Tab');
             }
             $updateDB = $db->Execute("insert into " . TABLE_EXTRA_TABS . " set\n\t\t  module_id = 'contacts',\n\t\t  tab_name = '" . SETUP_TITLE_EXTRA_FIELDS . "',\n\t\t  description = '" . SETUP_TITLE_EXTRA_FIELDS . "',\n\t\t  sort_order = '20'");
             $tab_id = db_insert_id();
             $result = $db->Execute("select * from " . DB_PREFIX . 'contacts_extra_fields');
             while (!$result->EOF) {
                 $params = unserialize($result->fields['params']);
                 // need to insert contact_type
                 $params['contact_type'] = $result->fields['contact_type'];
                 $updateDB = $db->Execute("insert into " . TABLE_EXTRA_FIELDS . " set\n\t\t    module_id = 'contacts',\n\t\t    tab_id = '" . $tab_id . "',\n\t\t    entry_type = '" . $result->fields['entry_type'] . "',\n\t\t    field_name = '" . $result->fields['field_name'] . "',\n\t\t    description = '" . $result->fields['description'] . "',\n\t\t    params = '" . serialize($params) . "'");
                 $result->MoveNext();
             }
             $db->Execute("DROP TABLE " . DB_PREFIX . "contacts_extra_fields");
         }
         xtra_field_sync_list('contacts', TABLE_CONTACTS);
     }
     if (MODULE_CONTACTS_STATUS < 3.5) {
         if (db_field_exists(TABLE_CURRENT_STATUS, 'next_cust_id_desc')) {
             $db->Execute("ALTER TABLE " . TABLE_CURRENT_STATUS . " DROP next_cust_id_desc");
         }
         if (db_field_exists(TABLE_CURRENT_STATUS, 'next_vend_id_desc')) {
             $db->Execute("ALTER TABLE " . TABLE_CURRENT_STATUS . " DROP next_vend_id_desc");
         }
         if (!db_field_exists(TABLE_CONTACTS, 'attachments')) {
             $db->Execute("ALTER TABLE " . TABLE_CONTACTS . " ADD attachments TEXT NOT NULL AFTER tax_id");
         }
     }
     if (MODULE_CONTACTS_STATUS < 3.7) {
         if (!db_field_exists(TABLE_CONTACTS_LOG, 'entered_by')) {
             $db->Execute("ALTER TABLE " . TABLE_CONTACTS_LOG . " ADD entered_by INT(11) NOT NULL DEFAULT '0' AFTER contact_id");
         }
     }
     if (MODULE_CONTACTS_STATUS < 3.72) {
         $db->Execute("ALTER TABLE " . TABLE_CONTACTS . " CHANGE tax_id tax_id INT(11) NOT NULL DEFAULT '-1';");
     }
     if (MODULE_CONTACTS_STATUS < 3.73) {
         if (!db_field_exists(TABLE_CONTACTS, 'contacts_level')) {
             $db->Execute("ALTER TABLE " . TABLE_CONTACTS . " ADD contacts_level CHAR(1) NOT NULL DEFAULT 'r' AFTER type;");
         }
         xtra_field_sync_list('contacts', TABLE_CONTACTS);
     }
     if (!db_field_exists(TABLE_CURRENT_STATUS, 'next_crm_id_num')) {
         $result = $db->Execute("Select MAX(short_name + 1) AS new  FROM " . TABLE_CONTACTS . " WHERE TYPE = 'i'");
         $db->Execute("ALTER TABLE " . TABLE_CURRENT_STATUS . " ADD next_crm_id_num VARCHAR( 16 ) NOT NULL DEFAULT '" . $result->fields['new'] . "';");
     }
     if (!$error) {
         write_configure('MODULE_' . strtoupper($module) . '_STATUS', constant('MODULE_' . strtoupper($module) . '_VERSION'));
         $messageStack->add(sprintf(GEN_MODULE_UPDATE_SUCCESS, $module, constant('MODULE_' . strtoupper($module) . '_VERSION')), 'success');
     }
     return $error;
 }
 function fields()
 {
     xtra_field_sync_list('assets', TABLE_ASSETS);
     $this->help_path = '';
 }
Example #5
0
 function update($module)
 {
     global $db, $messageStack, $currencies;
     $error = false;
     if (MODULE_INVENTORY_STATUS < 3.1) {
         $tab_map = array('0' => '0');
         if (db_table_exists(DB_PREFIX . 'inventory_categories')) {
             $result = $db->Execute("select * from " . DB_PREFIX . 'inventory_categories');
             while (!$result->EOF) {
                 $updateDB = $db->Execute("insert into " . TABLE_EXTRA_TABS . " set\n\t\t\t  module_id = 'inventory',\n\t\t\t  tab_name = '" . $result->fields['category_name'] . "',\n\t\t\t  description = '" . $result->fields['category_description'] . "',\n\t\t\t  sort_order = '" . $result->fields['sort_order'] . "'");
                 $tab_map[$result->fields['category_id']] = db_insert_id();
                 $result->MoveNext();
             }
             $db->Execute("DROP TABLE " . DB_PREFIX . "inventory_categories");
         }
         if (db_table_exists(DB_PREFIX . 'inventory_categories')) {
             $result = $db->Execute("select * from " . DB_PREFIX . 'inventory_fields');
             while (!$result->EOF) {
                 $updateDB = $db->Execute("insert into " . TABLE_EXTRA_FIELDS . " set\n\t\t\t  module_id = 'inventory',\n\t\t\t  tab_id = '" . $tab_map[$result->fields['category_id']] . "',\n\t\t\t  entry_type = '" . $result->fields['entry_type'] . "',\n\t\t\t  field_name = '" . $result->fields['field_name'] . "',\n\t\t\t  description = '" . $result->fields['description'] . "',\n\t\t\t  params = '" . $result->fields['params'] . "'");
                 $result->MoveNext();
             }
             $db->Execute("DROP TABLE " . DB_PREFIX . "inventory_fields");
         }
         xtra_field_sync_list('inventory', TABLE_INVENTORY);
     }
     if (MODULE_INVENTORY_STATUS < 3.2) {
         if (!db_field_exists(TABLE_PRICE_SHEETS, 'type')) {
             $db->Execute("ALTER TABLE " . TABLE_PRICE_SHEETS . " ADD type char(1) NOT NULL default 'c' AFTER sheet_name");
         }
         if (!db_field_exists(TABLE_INVENTORY, 'price_sheet_v')) {
             $db->Execute("ALTER TABLE " . TABLE_INVENTORY . " ADD price_sheet_v varchar(32) default NULL AFTER price_sheet");
         }
         xtra_field_sync_list('inventory', TABLE_INVENTORY);
     }
     if (MODULE_INVENTORY_STATUS < 3.6) {
         $db->Execute("ALTER TABLE " . TABLE_INVENTORY . " ADD INDEX ( sku )");
         if (!db_field_exists(TABLE_INVENTORY, 'attachments')) {
             $db->Execute("ALTER TABLE " . TABLE_INVENTORY . " ADD attachments text AFTER last_journal_date");
         }
         if (!db_field_exists(TABLE_INVENTORY, 'full_price_with_tax')) {
             $db->Execute("ALTER TABLE " . TABLE_INVENTORY . " ADD full_price_with_tax FLOAT NOT NULL DEFAULT '0' AFTER full_price");
         }
         if (!db_field_exists(TABLE_INVENTORY, 'product_margin')) {
             $db->Execute("ALTER TABLE " . TABLE_INVENTORY . " ADD product_margin FLOAT NOT NULL DEFAULT '0' AFTER full_price_with_tax");
         }
         if (!db_field_exists(TABLE_EXTRA_FIELDS, 'use_in_inventory_filter')) {
             $db->Execute("ALTER TABLE " . TABLE_EXTRA_FIELDS . " ADD use_in_inventory_filter ENUM( '0', '1' ) NOT NULL DEFAULT '0'");
         }
         $db->Execute("alter table " . TABLE_INVENTORY . " CHANGE inactive inactive ENUM( '0', '1' ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
         xtra_field_sync_list('inventory', TABLE_INVENTORY);
         $db->Execute("update " . TABLE_INVENTORY . " set inventory_type = 'ma' where inventory_type = 'as'");
         $result = $db->Execute("select * from " . TABLE_EXTRA_FIELDS . " where module_id = 'inventory'");
         while (!$result->EOF) {
             $temp = unserialize($result->fields['params']);
             switch ($result->fields['field_name']) {
                 case 'serialize':
                     $temp['inventory_type'] = 'sa:sr';
                     break;
                 case 'item_taxable':
                 case 'purch_taxable':
                 case 'item_cost':
                 case 'price_sheet':
                 case 'price_sheet_v':
                 case 'full_price':
                 case 'full_price_with_tax':
                 case 'product_margin':
                     $temp['inventory_type'] = 'ci:ia:lb:ma:mb:mi:ms:ns:sa:sf:si:sr:sv';
                     break;
                 case 'image_with_path':
                     $temp['inventory_type'] = 'ia:ma:mb:mi:ms:ns:sa:si:sr';
                     break;
                 case 'account_cost_of_sales':
                     $temp['inventory_type'] = 'ia:lb:ma:mb:mi:ms:ns:sa:sf:si:sr:sv';
                     break;
                 case 'cost_method':
                     $temp['inventory_type'] = 'ia:ma:mb:mi:ms:ns:si';
                     break;
                 case 'item_weight':
                     $temp['inventory_type'] = 'ia:ma:mb:mi:ms:ns:sa:si:sr';
                     break;
                 case 'quantity_on_hand':
                 case 'minimum_stock_level':
                 case 'reorder_quantity':
                     $temp['inventory_type'] = 'ia:ma:mi:ns:sa:si:sr';
                     break;
                 case 'quantity_on_order':
                 case 'quantity_on_allocation':
                     $temp['inventory_type'] = 'ia:mi:sa:si:sr';
                     break;
                 case 'quantity_on_sales_order':
                     $temp['inventory_type'] = 'ia:ma:mi:sa:si:sr';
                     break;
                 case 'lead_time':
                     $temp['inventory_type'] = 'ai:ia:lb:ma:mb:mi:ms:ns:sa:sf:si:sr:sv';
                     break;
                 case 'upc_code':
                     $temp['inventory_type'] = 'ia:ma:mi:ns:sa:si:sr';
                     break;
                 default:
                     $temp['inventory_type'] = 'ai:ci:ds:ia:lb:ma:mb:mi:ms:ns:sa:sf:si:sr:sv';
             }
             $updateDB = $db->Execute("update " . TABLE_EXTRA_FIELDS . " set params = '" . serialize($temp) . "' where id = '" . $result->fields['id'] . "'");
             $result->MoveNext();
         }
         $haystack = array('attachments', 'account_sales_income', 'item_taxable', 'purch_taxable', 'image_with_path', 'account_inventory_wage', 'account_cost_of_sales', 'cost_method', 'lead_time');
         $result = $db->Execute("update " . TABLE_EXTRA_FIELDS . " set entry_type = 'check_box' where field_name = 'inactive'");
         $result = $db->Execute("select * from " . TABLE_EXTRA_FIELDS . " where module_id = 'inventory'");
         while (!$result->EOF) {
             $use_in_inventory_filter = '1';
             if (in_array($result->fields['field_name'], $haystack)) {
                 $use_in_inventory_filter = '0';
             }
             $updateDB = $db->Execute("update " . TABLE_EXTRA_FIELDS . " set use_in_inventory_filter = '" . $use_in_inventory_filter . "' where id = '" . $result->fields['id'] . "'");
             $result->MoveNext();
         }
         if (!db_table_exists(TABLE_INVENTORY_PURCHASE)) {
             foreach ($this->tables as $table => $sql) {
                 if ($table == TABLE_INVENTORY_PURCHASE) {
                     admin_install_tables(array($table => $sql));
                 }
             }
             if (db_field_exists(TABLE_INVENTORY, 'purch_package_quantity')) {
                 $result = $db->Execute("insert into " . TABLE_INVENTORY_PURCHASE . " ( sku, vendor_id, description_purchase, purch_package_quantity, purch_taxable, item_cost, price_sheet_v ) select sku, vendor_id, description_purchase, purch_package_quantity, purch_taxable, item_cost, price_sheet_v  from " . TABLE_INVENTORY);
                 $db->Execute("ALTER TABLE " . TABLE_INVENTORY . " DROP purch_package_quantity");
             } else {
                 $result = $db->Execute("insert into " . TABLE_INVENTORY_PURCHASE . " ( sku, vendor_id, description_purchase, purch_package_quantity, purch_taxable, item_cost, price_sheet_v ) select sku, vendor_id, description_purchase, 1, purch_taxable, item_cost, price_sheet_v  from " . TABLE_INVENTORY);
             }
         }
         require_once DIR_FS_MODULES . 'phreebooks/functions/phreebooks.php';
         $tax_rates = ord_calculate_tax_drop_down('c');
         $result = $db->Execute("SELECT id, item_taxable, full_price, item_cost FROM " . TABLE_INVENTORY);
         while (!$result->EOF) {
             $sql_data_array = array();
             $sql_data_array['full_price_with_tax'] = round((1 + $tax_rates[$result->fields['item_taxable']]['rate'] / 100) * $result->fields['full_price'], $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
             if ($result->fields['item_cost'] != '' && $result->fields['item_cost'] > 0) {
                 $sql_data_array['product_margin'] = round($sql_data_array['full_price_with_tax'] / $result->fields['item_cost'], $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
             }
             db_perform(TABLE_INVENTORY, $sql_data_array, 'update', "id = " . $result->fields['id']);
             $result->MoveNext();
         }
         mkdir(DIR_FS_MY_FILES . $_SESSION['company'] . '/inventory/attachments/', 0755, true);
     }
     if (MODULE_INVENTORY_STATUS < 3.7) {
         if (!db_field_exists(TABLE_INVENTORY_HISTORY, 'avg_cost')) {
             $db->Execute("ALTER TABLE " . TABLE_INVENTORY_HISTORY . " ADD avg_cost FLOAT NOT NULL DEFAULT '0' AFTER unit_cost");
             $db->Execute("UPDATE " . TABLE_INVENTORY_HISTORY . " SET avg_cost = unit_cost");
         }
         $result = $db->Execute("select id, params from " . TABLE_EXTRA_FIELDS . " where module_id = 'inventory' AND field_name = 'account_cost_of_sales'");
         $temp = unserialize($result->fields['params']);
         $temp['inventory_type'] = 'ai:ci:ds:ia:lb:ma:mb:mi:ms:ns:sa:sf:si:sr:sv';
         $updateDB = $db->Execute("update " . TABLE_EXTRA_FIELDS . " set params='" . serialize($temp) . "' where id='" . $result->fields['id'] . "'");
         $db->Execute("ALTER TABLE " . TABLE_INVENTORY . "\n\t\t\tCHANGE item_cost item_cost DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE full_price full_price DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE full_price_with_tax full_price_with_tax DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE product_margin product_margin DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE item_weight item_weight DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE quantity_on_hand quantity_on_hand DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE quantity_on_order quantity_on_order DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE quantity_on_sales_order quantity_on_sales_order DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE quantity_on_allocation quantity_on_allocation DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE minimum_stock_level minimum_stock_level DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE reorder_quantity reorder_quantity DOUBLE NOT NULL DEFAULT '0'");
         $db->Execute("ALTER TABLE " . TABLE_INVENTORY_ASSY_LIST . " CHANGE qty qty double NOT NULL default '0'");
         $db->Execute("ALTER TABLE " . TABLE_INVENTORY_COGS_OWED . " CHANGE qty qty double NOT NULL default '0'");
         $db->Execute("ALTER TABLE " . TABLE_INVENTORY_COGS_USAGE . " CHANGE qty qty double NOT NULL default '0'");
         $db->Execute("ALTER TABLE " . TABLE_INVENTORY_HISTORY . "\n\t\t\tCHANGE qty qty DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE remaining remaining DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE unit_cost unit_cost DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE avg_cost avg_cost DOUBLE NOT NULL DEFAULT '0'");
         $db->Execute("ALTER TABLE " . TABLE_INVENTORY_PURCHASE . "\n\t\t\tCHANGE purch_package_quantity purch_package_quantity DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE item_cost item_cost DOUBLE NOT NULL DEFAULT '0'");
     }
     if (version_compare(MODULE_INVENTORY_STATUS, '3.7.4', '<')) {
         if (!db_field_exists(TABLE_INVENTORY, 'product_markup')) {
             $db->Execute("ALTER TABLE " . TABLE_INVENTORY . " CHANGE product_margin product_markup DOUBLE NOT NULL DEFAULT '0'");
             $db->Execute("ALTER TABLE " . TABLE_INVENTORY . " ADD product_margin DOUBLE NOT NULL DEFAULT '0' AFTER product_markup");
             $db->Execute("insert into " . TABLE_EXTRA_FIELDS . " set module_id = 'inventory', tab_id = '0', entry_type = 'decimal', field_name = 'product_markup',\n\t\t\t\tdescription = 'product_markup', params = 'a:2:{s:4:\"type\";N;s:14:\"inventory_type\";s:39:\"lb:ma:ia:mb:ms:ci:ns:sa:sr:sv:mi:sf:si:\";}'");
         }
         $result = $db->Execute("SELECT i.id, i.full_price, i.item_cost, max(p.item_cost) as purchase_cost FROM " . TABLE_INVENTORY . " i left join " . TABLE_INVENTORY_PURCHASE . " p on (p.sku = i.sku) ");
         while (!$result->EOF) {
             $sql_data_array = array();
             if ($result->fields['purchase_cost'] > $result->fields['item_cost']) {
                 $sql_data_array['product_margin'] = round(($result->fields['full_price'] - $result->fields['purchase_cost']) / $result->fields['full_price'] * 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
                 db_perform(TABLE_INVENTORY, $sql_data_array, 'update', "id = " . $result->fields['id']);
             } else {
                 $sql_data_array['product_margin'] = round(($result->fields['full_price'] - $result->fields['item_cost']) / $result->fields['full_price'] * 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
                 db_perform(TABLE_INVENTORY, $sql_data_array, 'update', "id = " . $result->fields['id']);
             }
             $result->MoveNext();
         }
     }
     if (!$error) {
         xtra_field_sync_list('inventory', TABLE_INVENTORY);
         write_configure('MODULE_' . strtoupper($module) . '_STATUS', constant('MODULE_' . strtoupper($module) . '_VERSION'));
         $messageStack->add(sprintf(GEN_MODULE_UPDATE_SUCCESS, $module, constant('MODULE_' . strtoupper($module) . '_VERSION')), 'success');
     }
     return $error;
 }