//"procmg.sc","Procedury dokumentu magazynowego","\Procedury\",0,1.0.0,SYSTEM

#include "Procedury Produkcja"
#include "MobileWarehouse - include"

int Sub OnAddNewDokument(long lId)
	OnAddNewDokument = 0
EndSub

int Sub OnBeforeInsert(long lId)
	OnBeforeInsert = DocumentToBuffer(0)
EndSub

int Sub OnAfterInsert(long lId)
	UnlockMg(lId)
	OnAfterInsert = 0
EndSub

int Sub OnKhChanged(long lId)
	OnKhChanged = 0
EndSub

int Sub OnBeforeEdit(long lId)
	int block = IsMgLocked(lId)
	if(block == 0) then
		LockMg(lId)
	endif
	OnBeforeEdit = 0
EndSub

int Sub OnBeforeBuforEdit(long lId)
	int block = IsMgLocked(lId)
	int createdByMobile = IsCreatedByMobile(lId)
	int createdByMobileLock = 0
	if(block == 0) then		
		if(createdByMobile == 0) then
			LockMg(lId)
			OnBeforeBuforEdit = 0
		else
			LockMg(lId)
			createdByMobileLock = DocumentCreatedByMobile()
			if(createdByMobileLock != 0) then
				UnlockMg(lId)
			endif
			OnBeforeBuforEdit = createdByMobileLock
		endif	
	else
		OnBeforeBuforEdit = DocumentInEditMode()
	endif
	//OnBeforeBuforEdit = 0
EndSub

int Sub OnAfterUpdate(long lId)
	UnlockMg(lId)
	OnAfterUpdate = 0
EndSub

int Sub OnAfterBuforUpdate(long lId)	
	IndicationOfDeliveries(lId)
	UnlockMg(lId)	
	OnAfterBuforUpdate = 0
EndSub

int Sub OnBeforeDelete(long lId)
	UnlockMg(lId)
	OnBeforeDelete = 0
	//OnBeforeDelete = CheckDokWarehouse(lId, 2) //PZF
EndSub

int Sub OnBeforeBuforDelete(long lId)
	int block = IsMgLocked(lId)
	int createdByMobile = IsCreatedByMobile(lId)
	int createdByMobileLock = 0
	if(block == 0) then
		if(createdByMobile == 0) then
			UnlockMg(lId)
			OnBeforeBuforDelete = 0
		else
			createdByMobileLock = DocumentCreatedByMobile()
			if(createdByMobileLock == 0) then
				UnlockMg(lId)
			endif
			OnBeforeBuforDelete = createdByMobileLock
		endif
	else
		OnBeforeBuforDelete = DocumentInEditMode()
	endif
EndSub

int Sub OnAfterDelete(long lId)
	UnlockMg(lId)
	OnAfterDelete = 0
EndSub

int Sub OnAfterBuforDelete(long lId)
	UnlockMg(lId)
	OnAfterBuforDelete = 0
EndSub

int Sub OnBeforeAnuluj(long lId)	
	OnBeforeAnuluj = 0
	//OnBeforeAnuluj = CheckDokWarehouse(lId, 1) //PZF
EndSub

int Sub OnTwChanged(long lId)
	OnTwChanged = 0
EndSub

int Sub OnBeforeCancel(long lId)
	OnBeforeCancel = 0
EndSub

int Sub OnAfterCancel(long lId)
	UnlockMg(lId)
	OnAfterCancel = 0
EndSub