Initial Commit of AgileBill Open Source
This commit is contained in:
182
modules/asset/asset.inc.php
Normal file
182
modules/asset/asset.inc.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AgileBill - Open Billing Software
|
||||
*
|
||||
* This body of work is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Open AgileBill License
|
||||
* License as published at http://www.agileco.com/agilebill/license1-4.txt
|
||||
*
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Agileco community forums at http://forum.agileco.com/
|
||||
*
|
||||
* @link http://www.agileco.com/
|
||||
* @copyright 2004-2008 Agileco, LLC.
|
||||
* @license http://www.agileco.com/agilebill/license1-4.txt
|
||||
* @author Tony Landis <tony@agileco.com>
|
||||
* @package AgileBill
|
||||
* @version 1.4.93
|
||||
*/
|
||||
|
||||
class asset
|
||||
{
|
||||
var $module = "asset";
|
||||
|
||||
/* check availibility */
|
||||
function available($assetPoolId, $qty=1) {
|
||||
$db=&DB();
|
||||
$rs = $db->Execute($sql=sqlSelect($db,"asset","id","(status=0 or status is null) and pool_id=::$assetPoolId::"));
|
||||
if($rs && $rs->RecordCount() >= $qty)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/* assign a asset to a specific service id from a specific asset pool */
|
||||
function assign($serviceId, $assetPoolId) {
|
||||
// check if any available
|
||||
$db=&DB();
|
||||
$rs = $db->Execute(sqlSelect($db,"asset","id,asset","(status=0 or status is null) and pool_id=::$assetPoolId::","",1));
|
||||
if($rs && $rs->RecordCount()) {
|
||||
$id = $rs->fields['id'];
|
||||
$asset = $rs->fields['asset'];
|
||||
$fields=Array('service_id'=>$serviceId, 'status'=>1, 'date_last'=>time());
|
||||
$db->Execute($sql=sqlUpdate($db,"asset",$fields,"id = $id"));
|
||||
return $asset;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** assign a known asset */
|
||||
function assignKnown($serviceId, $assetId) {
|
||||
$fields=Array('service_id'=>$serviceId, 'status'=>1, 'date_last'=>time());
|
||||
$db=&DB();
|
||||
$sql=sqlUpdate($db,"asset",$fields,"id = ::$assetId::");
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
/* un-assign a specific asset */
|
||||
function unAssign($assetId) {
|
||||
$db=&DB();
|
||||
$db->Execute($sql="UPDATE ".AGILE_DB_PREFIX."asset SET status='0',date_last='".time()."',service_id='0' WHERE id='$assetId'");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* un-assign all assets for a specific service */
|
||||
function unAssignAll($serviceId) {
|
||||
$db=&DB();
|
||||
$db->Execute($sql="UPDATE ".AGILE_DB_PREFIX."asset SET status='0',date_last='".time()."',service_id='0' WHERE service_id='$serviceId'");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* import assets */
|
||||
function import($VAR) {
|
||||
global $C_debug;
|
||||
if(empty($VAR['asset_pool_id'])) {
|
||||
$C_debug->alert("No asset pool specified");
|
||||
return;
|
||||
}
|
||||
|
||||
$db =& DB();
|
||||
if (is_uploaded_file($_FILES['datafile']['tmp_name'])) {
|
||||
# Got a file to import
|
||||
$fp = fopen($_FILES['datafile']['tmp_name'],"r");
|
||||
if ($fp) {
|
||||
$counter = 0; $skipped = 0;
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp,128);
|
||||
$cols=explode(",", $line);
|
||||
if(!empty($cols[0])) {
|
||||
$fields = Array(
|
||||
'date_orig'=>time(),
|
||||
'date_last'=>time(),
|
||||
'status'=>0,
|
||||
'service_id'=>0,
|
||||
'pool_id'=> $VAR['asset_pool_id'],
|
||||
'asset'=>@$cols[0],
|
||||
'misc'=>@$cols[1]);
|
||||
$db->Execute( sqlInsert($db, "asset", $fields) );
|
||||
$counter++;
|
||||
} else {
|
||||
$skipped++;
|
||||
}
|
||||
}
|
||||
$C_debug->alert("Imported $counter new Asset(s) and skipped $skipped Asset(s)!");
|
||||
} else {
|
||||
$C_debug->alert('Unable to fopen the file sent.');
|
||||
}
|
||||
} else {
|
||||
$C_debug->alert('Unable to process the uploaded file.');
|
||||
}
|
||||
}
|
||||
|
||||
function construct() {
|
||||
$this->xml_construct = PATH_MODULES . $this->module . "/" . $this->module . "_construct.xml";
|
||||
$C_xml = new CORE_xml;
|
||||
$construct = $C_xml->xml_to_array($this->xml_construct);
|
||||
$this->method = $construct["construct"]["method"];
|
||||
$this->trigger = $construct["construct"]["trigger"];
|
||||
$this->field = $construct["construct"]["field"];
|
||||
$this->table = $construct["construct"]["table"];
|
||||
$this->module = $construct["construct"]["module"];
|
||||
$this->cache = $construct["construct"]["cache"];
|
||||
$this->order_by = $construct["construct"]["order_by"];
|
||||
$this->limit = $construct["construct"]["limit"];
|
||||
}
|
||||
|
||||
function add($VAR) {
|
||||
$this->construct();
|
||||
$type = "add";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->add($VAR, $this, $type);
|
||||
}
|
||||
|
||||
function view($VAR) {
|
||||
$this->construct();
|
||||
$type = "view";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->view($VAR, $this, $type);
|
||||
}
|
||||
|
||||
function update($VAR) {
|
||||
$this->construct();
|
||||
$type = "update";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->update($VAR, $this, $type);
|
||||
}
|
||||
|
||||
function delete($VAR) {
|
||||
$this->construct();
|
||||
$db = new CORE_database;
|
||||
$db->mass_delete($VAR, $this, "");
|
||||
}
|
||||
|
||||
function search_form($VAR) {
|
||||
$this->construct();
|
||||
$type = "search";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search_form($VAR, $this, $type);
|
||||
}
|
||||
|
||||
function search($VAR) {
|
||||
$this->construct();
|
||||
$type = "search";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search($VAR, $this, $type);
|
||||
}
|
||||
|
||||
function search_show($VAR) {
|
||||
$this->construct();
|
||||
$type = "search";
|
||||
$this->method["$type"] = split(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search_show($VAR, $this, $type);
|
||||
}
|
||||
}
|
||||
?>
|
64
modules/asset/asset_construct.xml
Normal file
64
modules/asset/asset_construct.xml
Normal file
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||
<construct>
|
||||
<module>asset</module>
|
||||
<table>asset</table>
|
||||
<dependancy></dependancy>
|
||||
<cache>0</cache>
|
||||
<order_by>asset</order_by>
|
||||
<limit>35</limit>
|
||||
|
||||
<field>
|
||||
<id>
|
||||
<type>I8</type>
|
||||
<unique>1</unique>
|
||||
</id>
|
||||
<site_id>
|
||||
<type>I4</type>
|
||||
</site_id>
|
||||
<date_orig>
|
||||
<type>I8</type>
|
||||
<convert>date-now</convert>
|
||||
</date_orig>
|
||||
<date_last>
|
||||
<type>I8</type>
|
||||
<convert>date-now</convert>
|
||||
</date_last>
|
||||
<status>
|
||||
<type>L</type>
|
||||
</status>
|
||||
<service_id>
|
||||
<type>I8</type>
|
||||
</service_id>
|
||||
<pool_id>
|
||||
<type>I4</type>
|
||||
<asso_table>asset_pool</asso_table>
|
||||
<asso_field>name</asso_field>
|
||||
<validate>any</validate>
|
||||
</pool_id>
|
||||
<asset>
|
||||
<type>C(128)</type>
|
||||
<min_len>1</min_len>
|
||||
<max_len>128</max_len>
|
||||
</asset>
|
||||
<misc>
|
||||
<type>C(255)</type>
|
||||
</misc>
|
||||
</field>
|
||||
|
||||
<method>
|
||||
<add>id,site_id,date_orig,date_last,status,service_id,pool_id,asset,misc</add>
|
||||
<update>id,site_id,date_last,status,service_id,pool_id,asset,misc</update>
|
||||
<delete>id,site_id,date_orig,date_last,status,service_id,pool_id,asset,misc</delete>
|
||||
<view>id,site_id,date_orig,date_last,status,service_id,pool_id,asset,misc</view>
|
||||
<search>id,site_id,date_orig,date_last,status,service_id,pool_id,asset,misc</search>
|
||||
</method>
|
||||
|
||||
<index>
|
||||
<assets>id,site_id</assets>
|
||||
<asso>pool_id</asso>
|
||||
<service>service_id</service>
|
||||
<asset>asset</asset>
|
||||
</index>
|
||||
|
||||
<trigger>0</trigger>
|
||||
</construct>
|
47
modules/asset/asset_install.xml
Normal file
47
modules/asset/asset_install.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||
<install>
|
||||
<module_properties>
|
||||
<name>asset</name>
|
||||
<parent>asset</parent>
|
||||
<notes>Manage assets that can be assigned to services and maintain their availibility status</notes>
|
||||
<menu_display>1</menu_display>
|
||||
<dependancy></dependancy>
|
||||
<sub_modules>asset_pool</sub_modules>
|
||||
</module_properties>
|
||||
<sql_inserts>
|
||||
<module_method>
|
||||
<add>
|
||||
<name>add</name>
|
||||
<page>%%:add</page>
|
||||
<menu_display>1</menu_display>
|
||||
</add>
|
||||
<update>
|
||||
<name>update</name>
|
||||
</update>
|
||||
<delete>
|
||||
<name>delete</name>
|
||||
</delete>
|
||||
<view>
|
||||
<name>view</name>
|
||||
<page>core:search&module=%%&_escape=1</page>
|
||||
<menu_display>1</menu_display>
|
||||
</view>
|
||||
<search>
|
||||
<name>search</name>
|
||||
<page>%%:search_form</page>
|
||||
<menu_display>1</menu_display>
|
||||
</search>
|
||||
<search_form>
|
||||
<name>search_form</name>
|
||||
</search_form>
|
||||
<search_show>
|
||||
<name>search_show</name>
|
||||
</search_show>
|
||||
<import>
|
||||
<name>import</name>
|
||||
<page>%%:import</page>
|
||||
<menu_display>1</menu_display>
|
||||
</import>
|
||||
</module_method>
|
||||
</sql_inserts>
|
||||
</install>
|
49
modules/asset/generator.php
Normal file
49
modules/asset/generator.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AgileBill - Open Billing Software
|
||||
*
|
||||
* This body of work is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Open AgileBill License
|
||||
* License as published at http://www.agileco.com/agilebill/license1-4.txt
|
||||
*
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Agileco community forums at http://forum.agileco.com/
|
||||
*
|
||||
* @link http://www.agileco.com/
|
||||
* @copyright 2004-2008 Agileco, LLC.
|
||||
* @license http://www.agileco.com/agilebill/license1-4.txt
|
||||
* @author Tony Landis <tony@agileco.com>
|
||||
* @package AgileBill
|
||||
* @version 1.4.93
|
||||
*/
|
||||
|
||||
/*
|
||||
USAGE:
|
||||
|
||||
url/to/modules/asset/generator.php?prefix=MyPrefix&start=1&end=100
|
||||
|
||||
Where prefix a text prefix (defaults to asset- )
|
||||
Where start is the start of the count
|
||||
Where end is the end of the count
|
||||
|
||||
Paste to a text file and save for loading into the asset import tool.
|
||||
|
||||
*/
|
||||
|
||||
$prefix='asset-';
|
||||
$start=0;
|
||||
$end=1000;
|
||||
|
||||
@$prefix = $_GET['prefix'];
|
||||
@$start = $_GET['start'];
|
||||
@$end = $_GET['end'];
|
||||
|
||||
echo "<pre>";
|
||||
|
||||
while($start < $end) {
|
||||
echo $prefix.$start."\r\n";
|
||||
$start++;
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user