Bladeren bron

added edit notes in ZamZlec pro-netmedia

Piotr Labudda 9 jaren geleden
bovenliggende
commit
7ced169cd5
1 gewijzigde bestanden met toevoegingen van 130 en 0 verwijderingen
  1. 130 0
      SE/se-lib/Route/UrlAction/ProjektyProNetMediaZamZlec.php

+ 130 - 0
SE/se-lib/Route/UrlAction/ProjektyProNetMediaZamZlec.php

@@ -317,6 +317,7 @@ class Route_UrlAction_ProjektyProNetMediaZamZlec extends RouteBase {// TODO: Url
 		$id_company = V::get('id_company', 0, $data);
 		$items_count = V::get('items_count', 0, $data);
 		$widgetCompanies = V::get('widgetCompanies', array(), $data);
+		$saveOrderNotesLink = "index.php?_route=UrlAction_ProjektyProNetMediaZamZlec&_task=updateOrderNoteAjax";
 
 		$sqlWhere = '';
 		if ($id_project > 0) $sqlWhere = "where o.ID_PROJECT = {$id_project}";
@@ -384,11 +385,16 @@ class Route_UrlAction_ProjektyProNetMediaZamZlec extends RouteBase {// TODO: Url
 	</form>
 
 	<hr>
+<style type="text/css">
+.orders_cell__order_notes .edit_note_btn { display:none }
+.orders_cell__order_notes:hover .edit_note_btn { display:inline-block }
+</style>
 	<table class="table table-bordered table-hover">
 		<thead>
 			<tr>
 				<th>#</th>
 				<th>status</th>
+				<th>uwagi</th>
 				<th>nr zlecenia</th>
 				<th>nr budowy</th>
 			</tr>
@@ -435,6 +441,11 @@ class Route_UrlAction_ProjektyProNetMediaZamZlec extends RouteBase {// TODO: Url
 						<?php endforeach; ?>
 					<?php endif; ?>
 				</td>
+				<td class="orders_cell__order_notes">
+					<span class="order-notes"><?php echo $order['ORDER_NOTES']; ?></span>
+					<button onClick="return p5UI__Clickable(this, 'p5:ZamZlec:editNote', {idOrder: '<?= $order['ID']; ?>', label: '<?= $order['ORDER_LABEL']; ?>'})"
+						class="btn btn-xs btn-link edit_note_btn">Edytuj</button>
+				</td>
 				<td><?php echo $order['ORDER_LABEL']; ?></td>
 				<td><?php echo $order['obcy_nr_sprawy']; ?></td>
 			</tr>
@@ -442,6 +453,8 @@ class Route_UrlAction_ProjektyProNetMediaZamZlec extends RouteBase {// TODO: Url
 		</tbody>
 	</table>
 </div>
+<link rel="stylesheet" type="text/css" href="static/sweetalert2.min.css">
+<script src="static/sweetalert2.min.js"></script>
 <script>
 function submitZamowienie(fld) {
 	var frm = fld.form;
@@ -451,6 +464,94 @@ function submitZlecenie(fld) {
 	var frm = fld.form;
 	frm['_task'].value='addZlecenie';
 }
+
+(function() {
+	var _saveOrderNotesLink = "<?= $saveOrderNotesLink; ?>";
+	var _dbg = <?= (DBG::isActive()) ? "1" : "0" ?>;
+
+	jQuery(document).on('p5:ZamZlec:editNote:click', function(e, n, payload) {
+		if (!payload || !payload.props || !payload.props.idOrder) return false;
+		// TODO: load current value for field 'ORDER_NOTES' from ajax
+		// superagent
+		// 	.post(_saveOrderNotesLink)
+		// 	.type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
+		// 	.send({
+		// 		notes: orderNotes
+		// 	})
+		// 	.set('Accept', 'application/json')
+		// 	.end(function(err, res) {
+		// 		if(_dbg)console.log('#widget-zamzlec/editOrderNotes: res:', res, 'res.body:', res.body)
+		// 		if (err || !res.ok) {
+		// 			// jQuery(document).trigger('DBG:notify', {type: 'warning', msg: 'Req error', err: err});
+		// 			reject("Request error")
+		// 		} else {
+		// 			if ('application/json' !== res.type) {
+		// 				reject("Wrong response type - required json")
+		// 				return
+		// 			}
+		// 			if (!res.body.id || res.body.id <= 0) reject(res.body.msg || "Wystąpiły błędy podczas dodawaniu kosztu")
+		// 			resolve(res.body)
+		// 		}
+		// 	})
+		var orderNotes = jQuery(n).parent().find('.order-notes').text()
+		zamZlec__editOrderNote(n, payload.props.idOrder, payload.props.label || '', orderNotes);
+	});
+
+	function zamZlec__editOrderNote(n, idOrder, orderLabel, orderNotes) {
+		var noteNode = n;
+		console.log('TODO: edit note for idOrder('+idOrder+') orderNotes', orderNotes);
+		swal({
+		  title: 'Uwagi do zamówienia',
+			html: 'nr: "' + orderLabel + '" (id:'+idOrder+')',
+			animation: false,
+		  input: 'textarea',
+			inputPlaceholder: 'uwagi...',
+			inputValue: orderNotes,
+			// inputAttributes: {'step': '0.01'},
+		  showCancelButton: true,
+		  confirmButtonText: 'Zapisz',
+		  showLoaderOnConfirm: true,
+			showCloseButton: true,
+		  preConfirm: function(orderNotes) {
+		    return new Promise(function(resolve, reject) {
+					if (orderNotes.length > 255) reject('Przekroczono limit długości znaków')
+					superagent
+						.post(_saveOrderNotesLink)
+						.type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
+						.send({
+							id: idOrder,
+							notes: orderNotes
+						})
+						.set('Accept', 'application/json')
+						.end(function(err, res) {
+							if(_dbg)console.log('#widget-zamzlec/editOrderNotes: res:', res, 'res.body:', res.body)
+							if (err || !res.ok) {
+								reject((res.body && res.body.msg) ? res.body.msg  || "Request error" : "Request error")
+							} else {
+								if ('application/json' !== res.type) {
+									reject("Wrong response type - required json")
+									return
+								}
+								if (!res.body.order || res.body.order.ID <= 0) reject(res.body.msg || "Wystąpiły błędy")
+								resolve(res.body.order)
+							}
+						})
+		    })
+		  },
+		  allowOutsideClick: false
+		}).then(function(order) {
+			if(_dbg)console.log('#widget-zamzlec/editOrderNotes: order:', order)
+			zamZlec__renderNote(order.ID, order.ORDER_NOTES, n)
+		}).catch(function(e) {
+			// eg. hit Cancel
+		})
+	}
+
+	function zamZlec__renderNote(idOrder, notes, noteNode) {
+		console.log('TODO: edit note for idOrder('+idOrder+'), noteNode:', noteNode, 'notes:', notes);
+		jQuery(noteNode).parent().find('.order-notes').text(notes)
+	}
+})();
 </script>
 <?php
 	}
@@ -607,6 +708,31 @@ body { font-size:12px; line-height:1.3em }
 		exit;
 	}
 
+	public function updateOrderNoteAjaxAction() {
+		Response::sendTryCatchJson(array($this, 'updateOrderNoteAjax'), $args = 'JSON_FROM_REQUEST_BODY');
+	}
+	public function updateOrderNoteAjax($args) {
+		$response = array();
+		$response['type'] = "error";
+		if (DBG::isActive()) $response['DBG__ARGS'] = $args;
+		$id = V::get('id', 0, $args, 'int');
+		if ($id <= 0) throw new Exception("Error Processing Request - wrong id format");
+		$notes = V::get('notes', '', $args);
+		if (strlen($notes) > 255) throw new Exception("Przekroczono limit długości znaków");
+		$sqlObj = array();
+		$sqlObj['ID'] = $id;
+		$sqlObj['ORDER_NOTES'] = $notes;
+		$affected = DB::getDB()->UPDATE_OBJ('CRM_LISTA_ZASOBOW_ORDERS', (object)$sqlObj);
+		if (DBG::isActive()) $response['DBG__DB_affected'] = $affected;
+		if ($affected < 0) throw new Exception("Wystąpiły błędy podczas wprowadzania zmian");
+		$response['order'] = array();
+		$response['order']['ID'] = $id;
+		$response['order']['ORDER_NOTES'] = DB::getPDO()->fetchValue("select ORDER_NOTES from CRM_LISTA_ZASOBOW_ORDERS where ID = {$id}");
+		$response['msg'] = "TODO: L." . __LINE__;
+		$response['type'] = "success";
+		return $response;
+	}
+
 	public function saveAjaxAction() {
 		$body = Request::getRequestBody();
 		$json = json_decode($body, $assoc = true);
@@ -1282,4 +1408,8 @@ ALTER TABLE `CRM_LISTA_ZASOBOW_ORDERS` CHANGE `APPROVE_STATUS` `APPROVE_STATUS`
 1219		50		2/MK/8/SP/2016/V/2016				 2 / MK /  8/SP/2016 /    V / 2016
 1223		50		3/AS/8/SP/2016/V/2016				 3 / AS /  8/SP/2016 /    V / 2016
 
+-- ADD `ORDER_NOTES` - visible in orders list
+ALTER TABLE `CRM_LISTA_ZASOBOW_ORDERS`      ADD `ORDER_NOTES` varchar(255)     NOT NULL DEFAULT '';
+ALTER TABLE `CRM_LISTA_ZASOBOW_ORDERS_HIST` ADD `ORDER_NOTES` varchar(255) NOT NULL DEFAULT 'N/S;';
+
 */