Skip to content

Commit

Permalink
#2
Browse files Browse the repository at this point in the history
  • Loading branch information
pihel committed Dec 13, 2015
1 parent ccf0e8c commit 9a1f5fb
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 20 deletions.
8 changes: 8 additions & 0 deletions ajax/del_goal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?
require_once("../lib/init.php");
require_once("../lib/goal.php");

$goal = new Goal($db, $usr, $lng);
echo json_encode( $goal->delGoal($_GET['id']) );
?>

8 changes: 8 additions & 0 deletions ajax/goal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?
require_once("../lib/init.php");
require_once("../lib/goal.php");

$goal = new Goal($db, $usr, $lng);
echo json_encode( $goal->getList($_GET['uid']) );
?>

7 changes: 7 additions & 0 deletions ajax/save_goal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?
require_once("../lib/init.php");
require_once("../lib/goal.php");

$goal = new Goal($db, $usr, $lng);
echo $goal->saveGoal($_POST, &$ch);
?>
Binary file modified data/cash.db3
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/cash.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function del($id) {
return $cnt;
}

protected function add_refbook($name, $ref) {
public function add_refbook($name, $ref) {
if(!$this->usr->canWrite()) return NULL;

$ref_id = 0;
Expand Down
50 changes: 33 additions & 17 deletions lib/goal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
"nmcl_id" INTEGER NOT NULL,
"db_id" INTEGER NOT NULL,
"usr_id" INTEGER NOT NULL,
"date" DATE NOT NULL,
"plan" REAL
);
CREATE UNIQUE INDEX "XPK_CASHES_GOAL" on cashes_goal (id ASC);
CREATE UNIQUE INDEX "XIF_CASHES_GOAL_NDU" on cashes_goal (nmcl_id ASC, db_id ASC, usr_id ASC);
"plan_date" DATE,
"order_id" INTEGER,
"plan" REAL,
"qnt" REAL
)
CREATE UNIQUE INDEX "XPK_CASHES_GOAL" on cashes_goal (id ASC)
CREATE INDEX "XIF_CASHES_GOAL_DU" on cashes_goal (db_id ASC, usr_id ASC)
*/

class Goal {
Expand All @@ -23,47 +25,61 @@ public function __construct($_db, $_usr, $_lng) {
$this->lng = $_lng;
}

public function getList($uid = 0) {
public function getList($uid = -1) {
if(!$this->usr->canRead()) return array();

$sql =
"SELECT
cg.id, cg.db_id, cg.usr_id, cg.nmcl_id, cn.name, cg.`date`, cg.plan
cg.id, cg.db_id, cg.usr_id, cg.nmcl_id, cn.name as gname, cg.plan_date, cg.plan, cg.qnt, cg.order_id as iord
FROM
cashes_goal cg
INNER JOIN
cashes_nom cn
ON( cn.id = cg.nmcl_id )
WHERE
cg.db_id = ?
AND ( cg.usr_id = ? OR ? = 0 ) ";
AND ( cg.usr_id = ? OR ? = 0 )
ORDER BY cg.order_id, cg.plan_date ";

$this->db->escape_res = true;
if($uid == -1) $uid = 0;
return $this->db->select($sql, $this->usr->db_id, $uid, $uid);
} //getList

public function saveGoal($data) {
public function delGoal($id) {
if(!$this->usr->canWrite()) return $this->lng->get(159);
if(intval($id) < 1) return $this->lng->get(189);
$this->db->start_tran();
$this->db->exec("DELETE FROM cashes_goal WHERE id = ? ", $id );
$id = intval( $this->db->affect() );
$this->db->commit();
return $id;
} //delGoal

public function saveGoal($data, &$_ch) {
if(!$this->usr->canWrite()) return $this->lng->get(159);

if(intval($data['nmcl_id']) < 1) return $this->lng->get(189);
if(floatval($data['goal']) <= 0) return $this->lng->get(190);
if(!empty($data['date'])) return $this->lng->get(190);
$id = intval($data['id']);

$this->db->start_tran();

$nid = $_ch->add_refbook($data["gname"], "cashes_nom");
if( $nid == 0) { $this->db->rollback(); return $this->lng->get(164); }
$data['plan_date'] = str_replace("T00:00:00", "", $data['plan_date']);//???
if($id == 0) {
//insert

$this->db->exec("INSERT INTO cashes_goal(id, nmcl_id, db_id, usr_id, `date`, plan)
VALUES(NULL, ?, ?, ?, ?, ?)",
intval($data['grp_id']), $this->usr->db_id, $this->usr->id, floatval($data['plan']) );
$this->db->exec("INSERT INTO cashes_goal(id, nmcl_id, db_id, usr_id, `plan_date`, plan, qnt, order_id)
VALUES(NULL, ?, ?, ?, ?, ?, ?, ?)",
$nid, $this->usr->db_id, $this->usr->id, $data['plan_date'], floatval($data['plan']), floatval($data['qnt']), intval($data['iord']) );
$id = $this->db->last_id();
} else {
//update
$this->db->exec("UPDATE cashes_goal
SET plan = ?, `date` = ?
SET nmcl_id = ?, plan = ?, `plan_date` = ?, qnt = ?, order_id = ?
WHERE id = ? ",
floatval($data['plan']), $data['date'], $id );
$nid, floatval($data['plan']), $data['plan_date'], floatval($data['qnt']), intval($data['iord']), $id );
$id = intval( $this->db->affect() );
}

Expand Down
2 changes: 1 addition & 1 deletion lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$extjs = 'extjs';

/* App version */
$version = "1.056";
$version = "1.060";
//$version = rand(); //for reset cache

/* Path to imgs and js */
Expand Down
197 changes: 197 additions & 0 deletions static/js/goal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
var cash_goal_model = Ext.define('cash_goal_model', {
extend: 'Ext.data.Model',
id: "cash_goal_model",
fields: [
{name: 'id', type: 'int'},
{name: 'db_id', type: 'int'},
{name: 'usr_id', type: 'int'},
{name: 'nmcl_id', type: 'int'},
{name: 'gname', type: 'string'},
{name: 'plan', type: 'number'},
{name: 'qnt', type: 'number'},
{name: 'plan_date', type: 'date', dateFormat : "Y-m-d", submitFormat: 'Y-m-d'},
{name: 'iord', type: 'int'},
],
idProperty: 'id'
});

var cash_goal_store = Ext.create('Ext.data.Store', {
model: 'cash_goal_model',
id: "cash_goal_store",
autoLoad: false,
proxy: {
type: 'ajax',
url: 'ajax/goal.php'
}
}); //cash_goal_store

function getPluginGoalSave() {
if(parseInt(rights.write) != 1) return [];
return [Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})];
}

var cash_goal_add = Ext.create('Ext.button.Button', {
text: lang(49),
icon: settings.static + "/add.gif",
handler : function () {
cash_goal_store.add({id:0, plan: undefined, qnt:1, plan_date:undefined, iord:undefined});
}
}); //cash_goal_add

var cash_goal_id_name_model = Ext.define('cash_goal_id_name_model', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'}
],
idProperty: 'id'
});

var cash_goal_item_nmcl_store = Ext.create('Ext.data.Store', {
model: 'cash_goal_id_name_model',
//pageSize: 10,
proxy: {
// load using HTTP
type: 'ajax',
url: 'ajax/nmcl_list.php',
reader: {
type: 'json'
}
}
}); //cash_goal_item_nmcl_store

var cash_goal_item_nmcl_cb = Ext.create('Ext.form.field.ComboBox', {
store: cash_goal_item_nmcl_store,
id: "cash_goal_item_nmcl_cb",
name: "cash_goal_item_nmcl_cb",
labelWidth: 100,
displayField: 'name',
valueField: 'name',
minChars: 2,
allowBlank: false,
tpl: '<tpl for="."><div class="x-boundlist-item">{name:htmlEncode}</div></tpl>'
}); //cash_goal_item_nmcl_cb


var cash_goal_usr_name_list = Ext.create('Ext.data.Store', {
model: 'cash_goal_id_name_model',
autoDestroy: true,
proxy: {
// load using HTTP
type: 'ajax',
url: 'ajax/analiz/usr_list_analiz.php',
reader: {
type: 'json'
}
}
}); //cash_goal_usr_name_list

var cash_goal_usr_name_list_cb = Ext.create('Ext.form.field.ComboBox', {
store: cash_goal_usr_name_list,
id: "cash_goal_usr_name_list_cb",
name: "cash_goal_usr_name_list_cb",
fieldLabel: lang(30),
labelWidth: 100,
editable: false,
displayField: 'name',
valueField: 'id',
queryMode: 'local',
allowBlank: false,
value: uid,
listeners: {
select: function( combo, records, e) {
cash_goal_refresh();
}
}
}); //cash_goal_usr_name_list_cb

function cash_goal_refresh() {
var goal_uid = Ext.getCmp('cash_goal_usr_name_list_cb').getValue();
if(goal_uid == null) goal_uid = uid;

cash_goal_store.proxy.url = "ajax/goal.php?uid=" + goal_uid;
cash_goal_store.load();
} //cash_plan_mnth_refresh

var cash_goal_grid = Ext.create('Ext.grid.Panel', {
store: cash_goal_store,
id: "cash_goal_grid",
title: lang(83),
header: true,
width: Ext.getBody().getWidth() - 30,
height: Ext.getBody().getHeight() - 30,
forceFit: true,
tbar: [cash_goal_add],
columns: [
{text: "ID", dataIndex: 'id', hidden: true, tdCls: 'x-center-cell', width: 30 },
{text: lang(84), dataIndex: 'db_id', hidden: true, tdCls: 'x-center-cell', width: 30 },
{text: lang(29), dataIndex: 'usr_id', hidden: true, tdCls: 'x-center-cell', width: 30 },
{text: lang(16), dataIndex: 'nmcl_id', hidden: true, tdCls: 'x-center-cell', width: 30 },
{text: lang(17), dataIndex: 'gname', flex: true, editor: cash_goal_item_nmcl_cb},
{text: lang(78), dataIndex: 'plan' , editor: {xtype: 'numberfield', allowBlank: true}},
{text: lang(21), dataIndex: 'qnt' , editor: {xtype: 'numberfield', allowBlank: true}},
{text: "Дата", dataIndex: 'plan_date' , format: "Y-m-d", renderer: dateRender, field: {xtype: 'datefield', format: 'Y-m-d', submitFormat: 'Y-m-d', allowBlank: true }},
{text: "Приоритет", dataIndex: 'iord', editor: {xtype: 'numberfield', allowBlank: true} },
{
menuDisabled: true,
sortable: false,
hideable: false,
xtype: 'actioncolumn',
id: "cash_goal_edit_col",
width: 75,
items: [{
iconCls: 'del-cash-col',
tooltip: lang(37),
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
//rec.get('id')
if(rec.get('id') == 0) {
cash_goal_store.remove(rec);
} else {
Ext.Ajax.request({
url: "ajax/del_goal.php",
method: "GET",
params: {
id: rec.get('id')
},
success: function(data) {
if(parseInt(data.responseText) > 0) {
cash_goal_store.load();
} else {
error(data.responseText);
}
}//success
}); //Ext.Ajax.request
}
}
}, " ", {
icon: settings.static + "/yes.gif",
tooltip: lang(79),
handler: function(grid, rowIndex, colIndex) {
if(parseInt(rights.write) == 0) return;

var rec = grid.getStore().getAt(rowIndex);

Ext.Ajax.request({
url: "ajax/save_goal.php",
method: "POST",
params: rec.data,
success: function(data) {
if(parseInt(data.responseText) > 0) {
cash_goal_store.load();
} else {
error(data.responseText);
}
}//success
}); //Ext.Ajax.request
}
}]
}
],
selType: 'cellmodel',
plugins: getPluginGoalSave()
}); //cash_goal_grid

var loadMask_cash_goal_grid = new Ext.LoadMask(cash_goal_grid, {msg: lang(80), store: cash_goal_store});
6 changes: 5 additions & 1 deletion static/js/plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,17 @@ var cash_plan_goal_panel = Ext.create('Ext.Panel', {
id: "cash_plan_goal_panel",
border: false,
frame: true,
disabled: true,
//disabled: true,
title: lang(83),
items: [],
listeners: {
afterrender: function(){
loadScript(settings.static + "/js/goal.js", function() {
Ext.getCmp('cash_plan_goal_panel').add(Ext.getCmp('cash_goal_usr_name_list_cb'));
Ext.getCmp('cash_plan_goal_panel').add(Ext.getCmp('cash_goal_grid'));
Ext.getCmp('cash_goal_edit_col').setVisible(parseInt(rights.write) == 1);
cash_goal_usr_name_list.load();
cash_goal_refresh();
}); //loadScript
} //afterrender
}
Expand Down
2 changes: 2 additions & 0 deletions static/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ function price_r (val) {
}

function dateRender(value) {
if(value == undefined) return "";
var dt = new Date(value);
var val = Ext.Date.format(dt,'Y-m-d');
return val;
}

function dateTimeRender(value) {
if(value == undefined) return "";
var dt = new Date(value);
var val = Ext.Date.format(dt,'Y-m-d H:i');
return val;
Expand Down

0 comments on commit 9a1f5fb

Please sign in to comment.